isEnabled() || php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg') { return; } if (!empty($service->getConfig('panels')['DebugKit.Deprecations'])) { $errorLevel = Configure::read('Error.errorLevel', E_ALL | E_STRICT); $previousHandler = set_error_handler( function ($code, $message, $file, $line, $context = null) use (&$previousHandler) { if ($code == E_USER_DEPRECATED || $code == E_DEPRECATED) { DeprecationsPanel::addDeprecatedError(compact('code', 'message', 'file', 'line', 'context')); return; } if ($previousHandler) { $context['_trace_frame_offset'] = 1; return $previousHandler($code, $message, $file, $line, $context); } }, $errorLevel | E_USER_DEPRECATED | E_DEPRECATED ); } $hasDebugKitConfig = ConnectionManager::getConfig('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::setConfig('debug_kit', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Sqlite', 'database' => TMP . 'debug_kit.sqlite', 'encoding' => 'utf8', 'cacheMetadata' => true, 'quoteIdentifiers' => false, ]); } if (!CorePlugin::getCollection()->get('DebugKit')->isEnabled('routes')) { include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'routes.php'; } $appClass = Configure::read('App.namespace') . '\Application'; if (class_exists($appClass)) { EventManager::instance()->on('Server.buildMiddleware', function ($event, $queue) use ($service) { $middleware = new DebugKitMiddleware($service); $queue->insertAt(0, $middleware); }); } else { // Setup dispatch filter $debugBar = new DebugBarFilter(EventManager::instance(), (array)Configure::read('DebugKit')); $debugBar->setup(); DispatcherFactory::add($debugBar); } if (!function_exists('sql')) { /** * Prints out the SQL statements generated by a Query object. * * This function returns the same variable that was passed. * Only runs if debug mode is enabled. * * @param Query $query Query to show SQL statements for. * @param bool $showValues Renders the SQL statement with bound variables. * @param bool|null $showHtml If set to true, the method prints the debug * data in a browser-friendly way. * @return Query */ function sql(Query $query, $showValues = true, $showHtml = null) { return DebugSql::sql($query, $showValues, $showHtml, 1); } } if (!function_exists('sqld')) { /** * Prints out the SQL statements generated by a Query object and dies. * * Only runs if debug mode is enabled. * It will otherwise just continue code execution and ignore this function. * * @param Query $query Query to show SQL statements for. * @param bool $showValues Renders the SQL statement with bound variables. * @param bool|null $showHtml If set to true, the method prints the debug * data in a browser-friendly way. * @return void */ function sqld(Query $query, $showValues = true, $showHtml = null) { DebugSql::sqld($query, $showValues, $showHtml, 2); } }