use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\Log\Log;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use DebugKit\Routing\Filter\DebugBarFilter;
use PDO;
$debugBar = new DebugBarFilter(EventManager::instance(), (array) Configure::read('DebugKit'));
if (!$debugBar->isEnabled() || php_sapi_name() === 'cli') {
return;
}
$hasDebugKitConfig = ConnectionManager::config('debug_kit');
if (!$hasDebugKitConfig && !in_array('sqlite', PDO::getAvailableDrivers())) {
$msg = 'DebugKit not enabled. You need to either install pdo_sqlite, ' . 'or define the "debug_kit" connection name.';
Log::warning($msg);
return;
}
if (!$hasDebugKitConfig) {
ConnectionManager::config('debug_kit', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => TMP . 'debug_kit.sqlite', 'encoding' => 'utf8', 'cacheMetadata' => true, 'quoteIdentifiers' => false]);
}
Router::plugin('DebugKit', function ($routes) {
$routes->extensions('json');
$routes->connect('/toolbar/clear_cache', ['controller' => 'Toolbar', 'action' => 'clearCache']);
$routes->connect('/toolbar/*', ['controller' => 'Requests', 'action' => 'view']);
$routes->connect('/panels/view/*', ['controller' => 'Panels', 'action' => 'view']);
$routes->connect('/panels/*', ['controller' => 'Panels', 'action' => 'index']);
});
// Setup toolbar
$debugBar->setup();
DispatcherFactory::add($debugBar);