コード例 #1
0
 /**
  * @ignore
  */
 public function query($uQuery, array $uParameters = array(), $uCaching = null, $uModifies = false, $uSequence = null)
 {
     $this->connectionOpen();
     $tPreDebugInfo = array('query' => $uQuery, 'parameters' => $uParameters);
     if (Framework::$development) {
         if ($uModifies) {
             $this->beginTransaction();
         }
         if (!$uModifies || $this->explainOnModifies) {
             $tPreDebugInfo['explain'] = $this->queryArray(String::format($this->explainCommand, array('query' => $uQuery)), $uParameters);
         }
         if ($uModifies) {
             $this->rollBack();
         }
     }
     $this->logger->profilerStart($this->id . ' query', 'query', $tPreDebugInfo);
     if (!Framework::$disableCaches && $uCaching !== null) {
         $tCaching = (array) $uCaching;
         if (!isset($tCaching[1])) {
             $tOld = array_merge((array) $uQuery, $uParameters);
         } else {
             $tOld = (array) $tCaching[1];
         }
         if (!isset($tCaching[2])) {
             $tCaching[2] = 0;
         }
         $tCaching[1] = $this->id;
         $tCount = 0;
         foreach ($tOld as $tParameter) {
             $tCaching[1] .= ($tCount++ === 0 ? '/' : '_') . hash('adler32', $tParameter);
         }
         $tData = Datasources::get($tCaching[0])->cacheGet($tCaching[1]);
         if ($tData !== false) {
             $this->cache[$tCaching[1]] = $tData->resume($this);
             $tLoadedFromCache = true;
         } else {
             $tLoadedFromCache = false;
         }
     } else {
         $tCaching = null;
         $tData = false;
         $tLoadedFromCache = false;
     }
     if ($tData === false) {
         $tData = new DatabaseQueryResult($uQuery, $uParameters, $this, $tCaching, $uSequence);
         ++$this->stats['query'];
     } else {
         ++$this->stats['cache'];
     }
     //! affected rows
     $tPostDebugInfo = array('affectedRows' => $tData->count(), 'fromCache' => $tLoadedFromCache);
     $this->logger->profilerStop($tPostDebugInfo);
     return $tData;
 }
コード例 #2
0
ファイル: Logger.php プロジェクト: eserozvataf/scabbia1
 /**
  * Logs with an arbitrary level.
  *
  * @param string $uClass
  * @param mixed $uLevel
  * @param array $uContext
  * @return null
  */
 public static function write($uClass, $uLevel, array $uContext = array())
 {
     if (!isset($uContext['type'])) {
         $uContext['type'] = $uLevel === LogLevel::DEBUG || $uLevel === LogLevel::INFO ? 'log' : 'error';
     }
     self::$typeCounts[$uContext['type']]++;
     $uContext['class'] = $uClass;
     $uContext['category'] = $uLevel;
     $uContext['ip'] = $_SERVER['REMOTE_ADDR'];
     if (isset($uContext['message'])) {
         $uContext['message'] = String::prefixLines($uContext['message'], '- ', PHP_EOL);
     }
     if (isset($uContext['file'])) {
         if (Framework::$development) {
             $uContext['location'] = Io::extractPath($uContext['file']);
             if (isset($uContext['line'])) {
                 $uContext['location'] .= ' @' . $uContext['line'];
             }
         } else {
             $uContext['location'] = pathinfo($uContext['file'], PATHINFO_FILENAME);
         }
     } else {
         $uContext['location'] = '-';
     }
     $uContext['stackTrace'] = array();
     foreach (array_slice(debug_backtrace(), 2) as $tFrame) {
         $tArgs = array();
         /*
         if (isset($tFrame['args'])) {
             foreach ($tFrame['args'] as $tArg) {
                 $tArgs[] = var_export($tArg, true);
             }
         }
         */
         if (isset($tFrame['class'])) {
             $tFunction = $tFrame['class'] . $tFrame['type'] . $tFrame['function'];
         } else {
             $tFunction = $tFrame['function'];
         }
         if (isset($tFrame['file'])) {
             if (Framework::$development) {
                 $tLocation = Io::extractPath($tFrame['file']);
                 if (isset($tFrame['line'])) {
                     $tLocation .= ' @' . $tFrame['line'];
                 }
             } else {
                 $tLocation = pathinfo($tFrame['file'], PATHINFO_FILENAME);
             }
         } else {
             $tLocation = '-';
         }
         $uContext['stackTrace'][] = $tFunction . '(' . implode(', ', $tArgs) . ') in ' . $tLocation;
     }
     $uContext['eventDepth'] = Events::$eventDepth;
     Events::$disabled = true;
     if (!Framework::$readonly) {
         $tContent = '+ ' . String::format(Logger::$line, $uContext);
         $tFilename = Io::translatePath('{writable}logs/' . String::format(Logger::$filename, $uContext), true);
         Io::write($tFilename, $tContent, LOCK_EX | FILE_APPEND);
     }
     self::$console[] = $uContext;
     Events::$disabled = false;
     if (isset($uContext['halt']) && $uContext['halt']) {
         Events::invoke('reportError', $uContext);
         Framework::end(-1);
     }
 }