_enabled) { return null; } // make sure we have a query type if (null === $queryType) { switch (strtolower(substr(ltrim($queryText), 0, 6))) { case 'insert': $queryType = self::INSERT; break; case 'update': $queryType = self::UPDATE; break; case 'delete': $queryType = self::DELETE; break; case 'select': $queryType = self::SELECT; break; default: $queryType = self::QUERY; break; } } $query = new Profiler\Query($queryText, $queryType); $query->setSource($this->getSource()); $this->_queryProfiles[] = $query; end($this->_queryProfiles); return key($this->_queryProfiles); } protected function getSource() { $backtrace = debug_backtrace(); $search = [ '_lib' => [], 'site/App' => [], 'site/Qs' => [], ]; array_shift($backtrace); foreach ($backtrace as $item) { foreach ($search as $dir => &$info) { if (empty($item['file'])) { continue; } if (empty($info) && false !== ($pos = strpos($item['file'], $dir))) { $info = [ 'fileFullName' => $item['file'], 'file' => substr($item['file'], $pos), 'line' => $item['line'], 'class' => !empty($item['class']) ? $item['class'] : null, 'function' => $item['function'], 'type' => !empty($item['type']) ? $item['type'] : null, ]; } } } if (!empty($search['site/App'])) { return $search['site/App']; } return $search['_lib']; } }