public function notify()
 {
     // Erase buffer
     $buffer = ob_get_status();
     if (!empty($buffer)) {
         ob_end_clean();
     }
     if ($this->_observers->count()) {
         foreach ($this->_observers as $observer) {
             $observer->update($this);
         }
     }
     // Clear error for avoid multiple call
     if ($this->_clearErrorAfterSending) {
         $this->_error = false;
     }
     // Show internal server error (500)
     if (!Application::getDebug()) {
         Router::getInstance()->show500();
     }
     // Exit script
     exit;
 }
Example #2
0
 protected function _read($modelType, $slug)
 {
     $cache = $this->_cache->read($modelType . $slug);
     if (!is_null($cache) && !Application::getDebug()) {
         $data = $cache;
     } else {
         $manager = Model::factoryManager($modelType);
         $data = $manager->read($slug, true);
         //try by slug
         if (is_null($data)) {
             $data = $manager->read($slug);
         }
         //try by id
         if (!is_null($data)) {
             $this->_cache->write($modelType . $slug, $data, true);
         }
     }
     return $data;
 }
Example #3
0
 protected function _addLog($message, $level, $groupName = false, $isBacktrace = false, $notify = false)
 {
     if ($level <= $this->getLevel() || $this->getLevel() == self::DEBUG || Application::getDebug()) {
         // cache log
         if (self::getCache() && $level >= self::NOTICE && !Application::getDebug()) {
             $hash = md5($message . $level);
             $cache = self::getCache()->read($hash);
             // no exists, or epiress => write
             if (!$cache) {
                 self::getCache()->write($hash, $hash, true, $cache::EXPIRE_HOUR);
             } else {
                 return;
             }
             // no need log, because already exists in cache
         }
         // set log
         $date = new \DateTime('now');
         $log = new \stdClass();
         $log->message = $message;
         $log->level = $level;
         $log->group = $groupName;
         $log->date = $date->format('Y-m-d H:i:s');
         $log->isTrace = $isBacktrace;
         // add log on logs
         if ($groupName) {
             $this->_addLogOnGroup($groupName, $log);
         } else {
             $this->_logs[] = $log;
         }
         if (!$isBacktrace && self::getLogBacktrace()) {
             $this->_logBackTrace();
         }
         if ($notify) {
             $this->notify();
         }
     }
 }
Example #4
0
 public function execute($checkBindNumber = true)
 {
     if (Application::getDebug()) {
         Benchmark::getInstance($this->_configName)->startTime()->startRam();
     }
     if (is_null($this->_query) || !$this->_statement) {
         throw new \Exception('Prepare query before execute');
     }
     if ($checkBindNumber) {
         if (count($this->_params) < $this->_paramsNumberNecesary) {
             throw new \Exception('Miss bind parameters');
         }
     }
     // Bind parameters
     $i = 0;
     foreach ($this->_params as $param) {
         $bindName = $this->_bindParamType === Database::PARAM_BIND_POSITIONAL ? $i + 1 : ':' . $this->_namedParamOrder[$i];
         if ($param['isParam']) {
             $this->_statement->bindParam($bindName, $param['value'], $param['type']);
         } else {
             $this->_statement->bindValue($bindName, $param['value'], $param['type']);
         }
         $i++;
     }
     // Execute
     $this->_execute = $this->_statement->execute();
     //check error
     $lastError = $this->getLastError(true);
     if (!is_null($lastError)) {
         Logger::getInstance()->error('Sql query : ' . $this->_query . ' has error : ' . $lastError);
     }
     // Debug
     if (Application::getDebug()) {
         Database::getDatabase($this->_configName)->logQuery($this->_query, $this->_params, $this->_bindParamType, $lastError);
     }
     return $this->_execute;
 }