/**
  * Collects data
  *
  * @param TimeDataCollector $timeCollector
  * @return array
  */
 protected function collectData(TimeDataCollector $timeCollector = null)
 {
     $stmts = array();
     $total_duration = 0;
     $total_mem = 0;
     $failed = 0;
     $i = 0;
     $queries = $this->db->getQueries();
     $limit = DebugBar::config()->query_limit;
     $showDb = count(array_unique(array_map(function ($stmt) {
         return $stmt['database'];
     }, $queries))) > 1;
     foreach ($queries as $stmt) {
         $i++;
         $total_duration += $stmt['duration'];
         $total_mem += $stmt['memory'];
         if (!$stmt['success']) {
             $failed++;
         }
         if ($limit && $i > $limit) {
             $stmts[] = array('sql' => "Only the first {$limit} queries are shown");
             break;
         }
         $stmts[] = array('sql' => $stmt['short_query'], 'row_count' => $stmt['rows'], 'params' => $stmt['select'] ? $stmt['select'] : null, 'duration' => $stmt['duration'], 'duration_str' => $this->getDataFormatter()->formatDuration($stmt['duration']), 'memory' => $stmt['memory'], 'memory_str' => $this->getDataFormatter()->formatBytes($stmt['memory']), 'is_success' => $stmt['success'], 'database' => $showDb ? $stmt['database'] : null, 'source' => $stmt['source']);
         if ($timeCollector !== null) {
             $timeCollector->addMeasure($stmt['short_query'], $stmt['start_time'], $stmt['end_time']);
         }
     }
     return array('nb_statements' => count($queries), 'nb_failed_statements' => $failed, 'statements' => $stmts, 'accumulated_duration' => $total_duration, 'accumulated_duration_str' => $this->getDataFormatter()->formatDuration($total_duration), 'memory_usage' => $total_mem, 'memory_usage_str' => $this->getDataFormatter()->formatBytes($total_mem));
 }
 /**
  * @param MySQLDatabase $realConn
  */
 public function __construct($realConn)
 {
     $this->realConn = $realConn;
     $this->connector = $this->connector ?: $realConn->getConnector();
     $this->schemaManager = $this->schemaManager ?: $realConn->getSchemaManager();
     $this->queryBuilder = $this->queryBuilder ?: $realConn->getQueryBuilder();
     $this->queries = [];
     $this->findSource = DebugBar::config()->find_source;
 }
 public function index(SS_HTTPRequest $request)
 {
     if (!DebugBar::config()->enable_storage) {
         return $this->httpError(404, 'Storage not enabled');
     }
     $debugbar = DebugBar::getDebugBar();
     if (!$debugbar) {
         return $this->httpError(404, 'DebugBar not enabled');
     }
     $openHandler = new DebugBar\OpenHandler($debugbar);
     $openHandler->handle();
     exit;
     // Handle will echo and set headers
 }
 /**
  * Filter executed AFTER a request
  *
  * @param SS_HTTPRequest $request   Request container object
  * @param SS_HTTPResponse $response Response output object
  * @param DataModel $model          Current DataModel
  * @return boolean Whether to continue processing other filters. Null or true will continue processing (optional)
  */
 public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model)
 {
     $debugbar = DebugBar::getDebugBar();
     if (!$debugbar) {
         return;
     }
     // All queries have been displayed
     if (DebugBar::getShowQueries()) {
         exit;
     }
     $script = DebugBar::renderDebugBar();
     // If the bar is not renderable, return early
     if (!$script) {
         return;
     }
     // Inject init script into the HTML response
     $body = $response->getBody();
     if (strpos($body, '</body>') !== false) {
         $body = str_replace('</body>', $script . '</body>', $body);
         $response->setBody($body);
     }
     // Ajax support
     if (Director::is_ajax() && !headers_sent()) {
         if (DebugBar::IsAdminUrl() && !DebugBar::config()->enabled_in_admin) {
             return;
         }
         // Skip anything that is not a GET request
         if (!$request->isGET()) {
             return;
         }
         // Always enable in admin because everything is mostly loaded through ajax
         if (DebugBar::config()->ajax || DebugBar::IsAdminUrl()) {
             $headers = $debugbar->getDataAsHeaders();
             // Prevent throwing js errors in case header size is too large
             if (is_array($headers)) {
                 $debugbar->sendDataInHeaders();
             }
         }
     }
 }
 public static function includeRequirements()
 {
     $debugbar = self::getDebugBar();
     if (!$debugbar) {
         return;
     }
     // Already called
     if (self::$renderer) {
         return;
     }
     $renderer = $debugbar->getJavascriptRenderer();
     // We don't need the true path since we are going to use Requirements API that appends the BASE_PATH
     $renderer->setBasePath(DEBUGBAR_DIR . '/assets');
     $renderer->setBaseUrl(DEBUGBAR_DIR . '/assets');
     $renderer->disableVendor('jquery');
     $renderer->setEnableJqueryNoConflict(false);
     if (DebugBar::config()->enable_storage) {
         $renderer->setOpenHandlerUrl('__debugbar');
     }
     foreach ($renderer->getAssets('css') as $cssFile) {
         Requirements::css(ltrim($cssFile, '/'));
     }
     foreach ($renderer->getAssets('js') as $jsFile) {
         Requirements::javascript(ltrim($jsFile, '/'));
     }
     self::$renderer = $renderer;
 }
Exemple #6
0
 public static function setConfig($config)
 {
     if (isset($config['active'])) {
         self::$active = $config['active'];
         unset($config['active']);
     }
     if (self::isActive()) {
         if (isset($config['hidden'])) {
             self::$hidden = $config['hidden'];
             unset($config['hidden']);
         }
         if (isset($config['panels'])) {
             foreach ($config['panels'] as $panel) {
                 self::addPanel(new $panel());
             }
             unset($config['panels']);
         }
         self::$config = $config;
     }
 }
 /**
  * @param MySQLDatabase $realConn
  */
 public function __construct($realConn)
 {
     $this->realConn = $realConn;
     $this->queries = [];
     $this->findSource = DebugBar::config()->find_source;
 }