Whoops for CakePHP
, (*1)
Seamlessly integrate Whoops into CakePHP applications., (*2)
Demo-Video: Linux Mint + Firefox, (*3)
This branch is for use with CakePHP 5.0+. For details see version map., (*4)
Install
Using Composer:, (*5)
composer require dereuromark/cakephp-whoops
As this package only offers a Whoops handler for CakePHP, there is no need to
enable it (no ->addPlugin()
call). You only need to configure the renderer classes inside your config/app.php
or config/app_local.php
:, (*6)
'Error' => [
'exceptionRenderer' => \CakephpWhoops\Error\WhoopsExceptionRenderer::class,
'errorRenderer' => \CakephpWhoops\Error\WhoopsErrorRenderer::class
],
When using new Application.php and Middleware approach, you also need to adjust that:, (*7)
// Replace ErrorHandlerMiddleware with
->add(new \CakephpWhoops\Error\Middleware\WhoopsHandlerMiddleware(Configure::read('Error')))
Debug Mode
An important note: This plugin is installed as require dependency, but even so it is more used as require-dev one.
If the debug mode is off, it will completely ignore the Whoops handler, as without debug mode there is no exception to render.
It will then display the public error message and only log internally., (*8)
So make sure you enable debug (locally) for checking out this package.
For each error and exception you should then see the improved whoops handler output on your screen., (*9)
Editor
Opening the file in the editor via click in the browser is supported for most major IDEs.
It uses phpstorm://
URLs which can open the file through a command line call and directly jump to the right line., (*10)
Set your config as, (*11)
'Whoops' => [
'editor' => true,
],
To enable it., (*12)
If you are using a VM, e.g. CakeBox, you will also need the path mapping:, (*13)
'userBasePath' => 'C:\wamp\www\cakebox\Apps\my-app.local',
'serverBasePath' => '/home/vagrant/Apps/my-app.local',
If you would like to override the default URL handler (phpstorm://
) you could do so by setting the ideLinkPattern
option to a custom URL handler:, (*14)
- PhpStorm:
phpstorm://open?file=%s&line=%s
- Visual Studio Code:
vscode://file/%s:%s
See the Wiki for more details on different OS and Browsers., (*15)
Strictness
As a bonus the error handler is a bit more strict here for development.
It will not just ignore notices and other errors, but display them the same way in order to fix them with the same ease and speed as exceptions., (*16)
Usually, when a variable is not found, all following code can also not yield any useful results, as the example below shows.
Better to code cleaner in the first place and to avoid any warning or notice to be thrown in the first place., (*17)
Before:, (*18)
, (*19)
After:, (*20)
, (*21)