Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ php composer.phar require --dev cakephp/debug_kit "~3.0"
// src/Application.php
$this->addPlugin('DebugKit');
```
Prior to 3.6.0
```php
Plugin::load('DebugKit', ['bootstrap' => true, 'routes' => true]);
```
* Set `'debug' => true,` in `config/app.php`.

## Reporting Issues
Expand Down
46 changes: 0 additions & 46 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,10 @@
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Core\Configure;
use Cake\Core\Plugin as CorePlugin;
use Cake\Database\Query;
use Cake\Datasource\ConnectionManager;
use Cake\Event\EventManager;
use Cake\Log\Log;
use Cake\Routing\DispatcherFactory;
use DebugKit\DebugSql;
use DebugKit\Middleware\DebugKitMiddleware;
use DebugKit\Panel\DeprecationsPanel;
use DebugKit\Routing\Filter\DebugBarFilter;
use DebugKit\ToolbarService;

$service = new ToolbarService(EventManager::instance(), (array)Configure::read('DebugKit'));

if (!$service->isEnabled() || php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg') {
return;
}

if (!empty($service->getConfig('panels')['DebugKit.Deprecations'])) {
$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) {
return $previousHandler($code, $message, $file, $line, $context);
}
}
);
}

$hasDebugKitConfig = ConnectionManager::getConfig('debug_kit');
if (!$hasDebugKitConfig && !in_array('sqlite', PDO::getAvailableDrivers())) {
Expand All @@ -64,23 +35,6 @@ function ($code, $message, $file, $line, $context = null) use (&$previousHandler
]);
}

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.
Expand Down
17 changes: 0 additions & 17 deletions src/Cache/Engine/DebugEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,6 @@ public function groups(): array
return $this->_engine->groups();
}

/**
* Return the proxied configuration data.
*
* This method uses func_get_args() as not doing so confuses the
* proxied class.
*
* @deprecated 3.6.0 use setConfig()/getConfig() instead.
* @param string $key The key to set/read.
* @param mixed $value The value to set.
* @param bool $merge Whether or not configuration should be merged.
* @return mixed
*/
public function config($key = null, $value = null, $merge = true)
{
return call_user_func_array([$this->_engine, 'config'], func_get_args());
}

/**
* Returns the config.
*
Expand Down
45 changes: 0 additions & 45 deletions src/Controller/Component/ToolbarComponent.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Panel/RequestPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function shutdown(Event $event)
{
/* @var Controller $controller */
$controller = $event->getSubject();
$request = $controller->request;
$request = $controller->getRequest();
$this->_data = [
'params' => $request->getAttribute("params"),
'query' => $request->getQueryParams(),
Expand Down
2 changes: 1 addition & 1 deletion src/Panel/SessionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SessionPanel extends DebugPanel
public function shutdown(Event $event)
{
/* @var Request $request */
$request = $event->getSubject()->request;
$request = $event->getSubject()->getRequest();
if ($request) {
$this->_data = ['content' => $request->getSession()->read()];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Panel/VariablesPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function shutdown(Event $event)
return $item;
};
// Copy so viewVars is not mutated.
$vars = $controller->viewVars;
$vars = $controller->viewBuilder()->getVars();
array_walk_recursive($vars, $walker);

foreach ($vars as $k => $v) {
Expand Down
70 changes: 69 additions & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,78 @@
namespace DebugKit;

use Cake\Core\BasePlugin;
use Cake\Core\Configure;
use Cake\Core\PluginApplicationInterface;
use Cake\Event\EventManager;
use Cake\Http\MiddlewareQueue;
use DebugKit\Middleware\DebugKitMiddleware;
use DebugKit\Panel\DeprecationsPanel;

/**
* Plugin class for CakePHP 3.6.0 plugin collection.
* Plugin class for CakePHP plugin collection.
*/
class Plugin extends BasePlugin
{
/**
* @var \DebugKit\ToolbarService
*/
protected $service;

/**
* Load all the application configuration and bootstrap logic.
*
* @param \Cake\Core\PluginApplicationInterface $app The host application
* @return void
*/
public function bootstrap(PluginApplicationInterface $app): void
{
$service = new ToolbarService(EventManager::instance(), (array)Configure::read('DebugKit'));
$this->service = $service;

if (!$service->isEnabled() || php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg') {
return;
}

$this->setDeprecationHandler($service);

// will load `config/bootstrap.php`.
parent::bootstrap($app);
}
/**
* Add middleware for the plugin.
*
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to update.
* @return \Cake\Http\MiddlewareQueue
*/
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
{
if ($this->service) {
$middleware->add(new DebugKitMiddleware($this->service));
}

return $middleware;
}
/**
* set deprecation handler
*
* @param \DebugKit\ToolbarService $service The toolbar service instance
* @return void
*/
public function setDeprecationHandler($service)
{
if (!empty($service->getConfig('panels')['DebugKit.Deprecations'])) {
$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) {
return $previousHandler($code, $message, $file, $line, $context);
}
}
);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 9 additions & 6 deletions tests/TestCase/Panel/VariablesPanelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Cake\View\ViewVarsTrait;
use DebugKit\Panel\VariablesPanel;

/**
Expand Down Expand Up @@ -80,8 +81,10 @@ public function testShutdown()

$resource = fopen('data:text/plain;base64,', 'r');

$controller = new \stdClass();
$controller->viewVars = [
$controller = new class {
use ViewVarsTrait;
};
$controller->viewBuilder()->setVars([
'resource' => $resource,
'unserializableDebugInfo' => $unserializableDebugInfo,
'debugInfoException' => $debugInfoException,
Expand All @@ -91,7 +94,7 @@ public function testShutdown()
'result set' => $result,
'string' => 'yes',
'array' => ['some' => 'key']
];
]);
$event = new Event('Controller.shutdown', $controller);
$this->panel->shutdown($event);
$output = $this->panel->data();
Expand All @@ -108,14 +111,14 @@ public function testShutdown()
);
$this->assertInstanceOf(
'Cake\ORM\Query',
$controller->viewVars['query'],
$controller->viewBuilder()->getVar('query'),
'Original value should not be mutated'
);
$this->assertInternalType('array', $output['content']['updateQuery']);
$this->assertInternalType('array', $output['content']['query']);
$this->assertInternalType('array', $output['content']['unbufferedQuery']);
$this->assertInternalType('array', $output['content']['result set']);
$this->assertEquals($controller->viewVars['string'], $output['content']['string']);
$this->assertEquals($controller->viewVars['array'], $output['content']['array']);
$this->assertEquals($controller->viewBuilder()->getVar('string'), $output['content']['string']);
$this->assertEquals($controller->viewBuilder()->getVar('array'), $output['content']['array']);
}
}