4 function __($obj, $ret=false) {
9 if (!extension_loaded("xdebug")) {
10 Zend_Debug::dump($obj);
15 return ob_get_contents();
23 public $config = null;
25 public $VARS = array();
27 public function __constructor() {
28 # nothing to do for the moment
31 public function boot($bootorder = array()) {
34 if (empty($bootorder)) {
35 $bootOrder = array('Domain', 'PHPConfig', 'IncludePath', 'Zend', 'Config', 'DB');
37 foreach ($bootOrder as $fn) {
43 private function initDomain() {
44 if (!empty($this->VARS['domain'])) {
45 $_SERVER['REQUEST_URI'] = str_replace('/'.$this->VARS['domain'], '/', $_SERVER['REQUEST_URI']);
48 $defaultDomain = 'en';
50 if (empty($this->VARS['controller']) || (false === strstr($_SERVER['REQUEST_URI'], $this->VARS['controller']))) {
51 $url = $_SERVER['REQUEST_URI'] . $defaultDomain . '/';
53 $url = str_replace('/'.$this->VARS['controller'].'/', '/'.$defaultDomain.'/'.$this->VARS['controller'].'/', $_SERVER['REQUEST_URI']);
55 header('Location: ' . $url);
60 private function initPHPConfig() {
61 # Be sure that you're showing all errors
62 ini_set('display_errors', true);
63 ini_set('error_reporting', E_ALL | E_STRICT);
65 # timezone is always a problem when not set
66 ini_set('date.timezone', 'Europe/Paris');
70 private function initIncludePath() {
71 $includePath = array('.', './site/models/');
74 foreach(new DirectoryIterator($libDir) as $value) {
75 $path = $libDir . $value;
76 if (is_dir($path) && (!in_array((string)$value,array('.','..')))) {
77 $includePath[] = $path;
81 set_include_path(get_include_path() . PATH_SEPARATOR . implode(PATH_SEPARATOR, $includePath));
84 private function initZend() {
86 require_once('Zend/Loader.php');
87 Zend_Loader::registerAutoload();
90 Zend_Session::start();
92 # controller configuration
93 $controller = Zend_Controller_Front::getInstance();
94 $controller->setControllerDirectory('./site/controllers/');
95 $controller->setDefaultControllerName('Index');
96 $controller->throwExceptions(true);
99 $view = new Zend_View(array('encoding' => 'UTF-8'));
100 $view->setScriptPath('./site/views/Pages/');
101 $view->setHelperPath('./site/views/Helpers/');
103 # modify the viewRenderer default behaviour
104 $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
105 $viewRenderer->setView($view);
106 $viewRenderer->setViewSuffix('php');
109 private function initVars() {
110 $this->VARS = array();
111 if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
112 $this->VARS['_ajax'] = true;
114 if (isset($_SESSION)) {
115 $this->VARS = array_merge($this->VARS, $_SESSION);
117 $this->VARS = array_merge($this->VARS, $_COOKIE, $_GET, $_POST);
120 private function initConfig() {
121 $this->config = new Zend_Config_Ini('config.ini', 'live');
124 private function initDB() {
125 $dbtype = $this->config->db->type;
127 'host' => $this->config->db->host,
128 'username' => $this->config->db->user,
129 'password' => $this->config->db->password,
130 'dbname' => $this->config->db->name
133 $this->db = Zend_Db::factory($dbtype, $params);
136 public static function displayError(Exception $e) {
137 echo '<!-- ERROR -->';
138 echo '<style type="text/css">';
139 echo '#mainPanelError {';
140 echo ' text-align:left;';
141 echo ' padding:10px;';
142 echo ' background:#ffea50;';
143 echo ' border:4px double red;';
145 echo '#stackTrace {';
146 echo ' text-align:left;';
147 echo ' background:white;';
148 echo ' border:1px solid black;';
149 echo ' margin:30px;';
151 echo '.stackTraceElement {';
152 echo ' text-align:left;';
153 echo ' background:white;';
154 echo ' margin:0 0 5px 0;';
157 echo ' font-size:0.8em;';
158 echo ' color:#999999;';
159 echo ' margin:0 0 0 15px;';
162 echo '<div id="mainPanelError"><strong>';
165 echo $e->getMessage();
167 $trace = $e->getTrace();
169 function getInfo($traceElt, $param = false) {
170 $info = array_key_exists('class', $traceElt) ? $traceElt['class'] . $traceElt['type'] : '';
171 $info .= $traceElt['function'];
173 if ($traceElt['args']) {
174 $count = count($traceElt['args']);
175 for ($i = 0; $i < $count; $i++) {
176 $arg = $traceElt['args'][$i];
177 $info .= is_object($arg) ? get_class($arg) : gettype($arg);
178 if ($i < $count - 1) {
184 if ($traceElt['args'] && $param) {
185 $info .= __($traceElt['args'], 'func_get_args(): ', false);
189 echo '<br /><em>in '.getInfo($trace[0], true).'</em>';
190 echo '<div id="stackTrace">';
191 echo '<b>StackTrace :</b><br /><br />';
192 foreach ($trace as $k => $line) {
193 echo '<div class="stackTraceElement">';
194 $callInfo = ($k < count($trace) - 1) ? getInfo($trace[$k + 1]) : "";
196 if (array_key_exists('file', $line)) {
197 echo ' (' .basename($line['file']) .':'.$line['line'].')<br />';
198 echo '<span class="fileInfo">in file '.$line['file'].'</span>';