How can I get a debug toolbar for my Expressive application?
Many modern frameworks and applications provide debug toolbars: in-browser toolbars to provide profiling information of the request executed. These can provide invaluable details into application objects, database queries, and more. As an Expressive user, how can you get similar functionality?
Zend Server Z-Ray
Zend Server ships with a tool called Z-Ray, which provides both a debug toolbar and debug console (for API debugging). Z-Ray is also currently available as a standalone technology preview, and can be added as an extension to an existing PHP installation.
When using Zend Server or the standalone Z-Ray, you do not need to make any changes to your application whatsoever to benefit from it; you simply need to make sure Z-Ray is enabled and/or that you've setup a security token to selectively enable it on-demand. See the Z-Ray documentation for full usage details.
Another option is bitExpert's prophiler-psr7-middleware. This package wraps fabfuel/prophiler, which provides a PHP-based profiling tool and toolbar; the bitExpert package wraps this in PSR-7 middleware to make consumption in those paradigms trivial.
To add the toolbar middleware to your application, use composer:
$ composer require bitExpert/prophiler-psr7-middleware
From there, you will need to create a factory for the middleware, and add it to your middleware pipeline. Stephan Hochdörfer, author of the package, has written a post detailing these steps.
One minor change we recommend over the directions Stephan provides is that you configure the factory and middleware in the
config/autoload/middleware-pipeline.local.phpfile, vs the
.globalversion. Doing so enables the middleware and toolbar only in the local environment — and not in production, where you likely do not want to expose such information!
First, install the middleware in your application:
$ composer require php-middleware/php-debug-bar
This package provides a config provider. You can add it to your application in one of two ways:
- If you are using the ConfigManager, add an entry for it:
$configManager = new Zend\Expressive\ConfigManager\ConfigManager([
- If you are not using the ConfigManager, create a new configuration file,
config/autoload/php-debugbar.global.php, with the following contents:
```php <?php use PhpMiddleware\PhpDebugBar\ConfigProvider;
$provider = new ConfigProvider(); return $provider(); ```
Remember to enable
PhpMiddleware\PhpDebugBar\ConfigProvideronly in your development enviroments!