public function __destruct()
 {
     if (!empty($this->_logs)) {
         if (!Http::isAjax()) {
             if (!Cli::isCli()) {
                 echo '<pre>';
             }
             echo $this->_logs;
             if (!Cli::isCli()) {
                 echo '</pre>';
             }
         }
     }
 }
 protected function __construct()
 {
     if (!extension_loaded('session')) {
         throw new \Exception('Session extension not loaded try change your PHP configuration');
     }
     Logger::getInstance()->addGroup('session', 'Session report', true, true);
     Logger::getInstance()->debug('Session class has been instantiated', 'session');
     if (Cli::isCli()) {
         Logger::getInstance()->debug('Use session on cli', 'session');
     }
     // Securise
     if (self::getSecurise()) {
         $this->add(self::getSecurityKeyName(), $this->_generateSecurity(), true, true);
         Logger::getInstance()->debug('Session was securised', 'session');
     }
 }
 public function run()
 {
     if ($this->_isRun) {
         throw new \Exception('Application already runned');
     }
     //Cli
     if (Cli::isCli()) {
         throw new \Exception('CLI not yet');
     }
     // Check maitenance mode activated => show503
     if (defined('SITE_MAINTENANCE') && SITE_MAINTENANCE) {
         Router::getInstance()->show503();
     } else {
         // Run router
         Router::getInstance()->run();
     }
     $this->_isRun = true;
 }
 public function __construct()
 {
     if (!Cli::isCli()) {
         $this->_chrome = \ChromePHP::getInstance();
     }
 }
 public function __construct()
 {
     if (!Cli::isCli()) {
         $this->_fb = \FirePHP::getInstance(true);
     }
 }
 protected function _runController($controller, $methods = array(), $vars = array(), $requireSsl = false, $requireAjax = false, $autoSetAjax = true, $requireHttpMethod = null, $httpResponseStatusCode = null, $httpProtocol = null)
 {
     $controllerExplode = explode($this->getNamespaceSeparator(), (string) $controller);
     if (is_array($controllerExplode) && count($controllerExplode) > 1) {
         $controllerName = $this->getNamespaceSeparator() . ucfirst(array_pop($controllerExplode));
         $controller = implode($this->getNamespaceSeparator(), $controllerExplode) . $controllerName;
     } else {
         $controller = (string) ucfirst($controller);
     }
     Logger::getInstance()->debug('Run controller : "' . $controller . '"', 'router');
     $controllerClass = $this->getControllersNamespace(true) . $controller;
     // Check if controller exists (with controllers namespace)
     if (!class_exists($controllerClass)) {
         throw new \Exception('Controller "' . $controllerClass . '" not found');
     }
     $controller = $controllerClass;
     if (!is_array($vars)) {
         throw new \Exception('Controller : "' . $controller . '" vars must be an array');
     }
     if (!is_array($methods)) {
         throw new \Exception('Controller : "' . $controller . '" methodes must be an array');
     }
     $inst = new \ReflectionClass($controller);
     if ($inst->isInterface() || $inst->isAbstract()) {
         throw new \Exception('Controller "' . $controller . '" cannot be an interface of an abstract class');
     }
     $ctrl = $inst->newInstance();
     if ($ctrl->getAutoCallDisplay()) {
         if (!$inst->hasMethod('display')) {
             throw new \Exception('Controller "' . $controller . '" must be implement method "Diplay');
         }
         if (!$inst->hasMethod('initTemplate')) {
             throw new \Exception('Controller "' . $controller . '" must be implement method "initTemplate');
         }
     }
     if (!Cli::isCli()) {
         if (!Http::isHttps() && $requireSsl) {
             Logger::getInstance()->debug('Controller "' . $controller . '" need ssl http request', 'router');
             $this->show400(true);
         }
         if (!is_null($requireHttpMethod)) {
             if ($requireHttpMethod != Http::getMethod()) {
                 Logger::getInstance()->debug('Controller "' . $controller . '" invalid http method');
                 $this->show405(true);
             }
         }
         if (!Http::isAjax() && $requireAjax) {
             Logger::getInstance()->debug('Controller "' . $controller . '" need ajax http request');
             $this->show400(true);
         }
         if (Http::isAjax() && $autoSetAjax) {
             $ctrl->setAjaxController();
         }
         if (!is_null($httpResponseStatusCode) || !is_null($httpProtocol)) {
             Header::setResponseStatusCode(is_null($httpResponseStatusCode) ? 200 : $httpResponseStatusCode, true, true, $httpProtocol);
         }
     }
     if ($methods) {
         foreach ($methods as $methodName => $methodParams) {
             Logger::getInstance()->debug('Call method : "' . $methodName . '"', 'router');
             if (!method_exists($ctrl, $methodName) || !$inst->getMethod($methodName)->isPublic()) {
                 throw new \Exception('Method "' . $methodName . '" don\'t exists or isn\'t public on controller "' . $controller . '"');
             }
             $args = array();
             if (!is_array($methodParams)) {
                 $args[] = $methodParams;
             } else {
                 foreach ($methodParams as $parameter) {
                     //check if is [['key']] type, or direct value
                     if (stripos($parameter, '[[') === false) {
                         $args[] = $parameter;
                     } else {
                         if (count($vars) > 0) {
                             $key = (int) str_replace(array('[', ']'), '', $parameter);
                             if (array_key_exists($key, $vars)) {
                                 $args[] = $vars[$key];
                             }
                         } else {
                             $args[] = $parameter;
                         }
                     }
                 }
             }
             foreach ($args as $arg) {
                 Logger::getInstance()->debug('Add argument : "' . $arg . '"', 'router');
             }
             // Call method with $args
             \call_user_func_array(array($ctrl, $methodName), $args);
         }
     }
     $this->_controller = $ctrl;
     //call display only when have a template
     if ($ctrl->getAutoCallDisplay() && Template::getTemplate()) {
         Logger::getInstance()->debug('Call method "display"', 'router');
         $ctrl->display();
     }
 }