/**
  * Get the Debug Bar instance
  *
  * @global array $databaseConfig
  * @return DebugBar\StandardDebugBar
  */
 public static function getDebugBar()
 {
     if (self::$debugbar !== null) {
         return self::$debugbar;
     }
     if (!Director::isDev() || self::IsDisabled() || self::VendorNotInstalled() || self::NotLocalIp() || Director::is_cli() || self::IsDevUrl() || self::IsAdminUrl() && !self::config()->enabled_in_admin) {
         self::$debugbar = false;
         // No need to check again
         return;
     }
     // Add the controller extension programmaticaly because it might not be added properly through yml
     Controller::add_extension('DebugBarControllerExtension');
     // Add a custom logger that logs everything under the Messages tab
     SS_Log::add_writer(new DebugBarLogWriter(), SS_Log::DEBUG, '<=');
     self::$debugbar = $debugbar = new DebugBar\DebugBar();
     if (isset($_REQUEST['showqueries'])) {
         self::setShowQueries(true);
         echo "The queries above have been run before we started DebugBar";
         echo '<hr>';
         unset($_REQUEST['showqueries']);
     }
     $debugbar->addCollector(new DebugBar\DataCollector\PhpInfoCollector());
     $debugbar->addCollector(new DebugBar\DataCollector\MessagesCollector());
     $debugbar->addCollector(new DebugBar\DataCollector\TimeDataCollector());
     $debugbar->addCollector(new DebugBar\DataCollector\MemoryCollector());
     // On 3.1, PDO does not exist
     if (method_exists('DB', 'get_conn')) {
         if (!DB::get_conn()) {
             global $databaseConfig;
             if ($databaseConfig) {
                 DB::connect($databaseConfig);
             }
         }
         $connector = DB::get_connector();
         if (!self::config()->force_proxy && $connector instanceof PDOConnector) {
             // Use a little bit of magic to replace the pdo instance
             $refObject = new ReflectionObject($connector);
             $refProperty = $refObject->getProperty('pdoConnection');
             $refProperty->setAccessible(true);
             $traceablePdo = new DebugBar\DataCollector\PDO\TraceablePDO($refProperty->getValue($connector));
             $refProperty->setValue($connector, $traceablePdo);
             $debugbar->addCollector(new DebugBar\DataCollector\PDO\PDOCollector($traceablePdo));
         } else {
             DB::set_conn($db = new DebugBarDatabaseNewProxy(DB::get_conn()));
             $db->setShowQueries(self::getShowQueries());
             $debugbar->addCollector(new DebugBarDatabaseCollector($db));
         }
     } else {
         if (!DB::getConn()) {
             global $databaseConfig;
             if ($databaseConfig) {
                 DB::connect($databaseConfig);
             }
         }
         DB::setConn($db = new DebugBarDatabaseProxy(DB::getConn()));
         $db->setShowQueries(self::getShowQueries());
         $debugbar->addCollector(new DebugBarDatabaseCollector($db));
     }
     // Add some SilverStripe specific infos
     $debugbar->addCollector(new DebugBarSilverStripeCollector());
     if (self::config()->enable_storage) {
         $debugbar->setStorage(new DebugBar\Storage\FileStorage(TEMP_FOLDER . '/debugbar'));
     }
     // Since we buffer everything, why not enable all dev options ?
     if (self::config()->auto_debug) {
         $_REQUEST['debug'] = true;
         $_REQUEST['debug_request'] = true;
     }
     if (isset($_REQUEST['debug']) || isset($_REQUEST['debug_request'])) {
         self::$bufferingEnabled = true;
         ob_start();
         // We buffer everything until we have called an action
     }
     return $debugbar;
 }
 /**
  * Add all the collectors to the debugbar
  *
  * @return  void
  */
 public function addCollectors()
 {
     foreach ($this->config->collectors as $collector) {
         $this->debugbar->addCollector(new $collector());
     }
 }