Exemplo n.º 1
0
 /**
  * @param string $sql
  */
 public function start($sql)
 {
     // find caller
     $context = array();
     $ns = str_replace('\\', '/', __NAMESPACE__);
     $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10);
     foreach ($backtrace as $i => $trace) {
         if (strpos($trace['file'], $ns) === false) {
             switch ($trace['class']) {
                 case 'Graphite\\Db\\Connection':
                 case 'Graphite\\Db\\Query\\AbstractQuery':
                     $next = $backtrace[$i + 1];
                     $initiator = $this->_formatClass($next['class'], $next['type'], $next['function']);
                     break;
                 case 'Graphite\\Db\\ActiveRecord\\Model':
                     $initiator = $this->_formatClass($this->staticCaller, $trace['type'], $trace['function']);
                     break;
                 case 'Graphite\\Db\\ActiveRecord\\Finder':
                     $initiator = $this->_formatClass($this->staticCaller, $trace['type'], 'find');
                     break;
                 default:
                     $initiator = $this->_formatClass($trace['class'], $trace['class'], $trace['function']);
             }
             $context['initiator'] = $initiator;
             $context['file'] = empty($this->basePath) ? $trace['file'] : str_replace($this->basePath, '', $trace['file']);
             $context['line'] = $trace['line'];
             break;
         }
     }
     $this->query = array('sql' => $sql, 'start' => microtime(true), 'type' => $this->parseType($sql), 'table' => SqlParser::parseTableName($sql), 'context' => $context);
     if ($this->callback) {
         call_user_func($this->callback, 'start', $this->query);
     }
 }