PHP Debug bar PSR-15 middleware with PSR-7. Also supports PSR-11
This middleware provide framework-agnostic possibility to attach PHP Debug Bar to your response (html on non-html!).
composer require php-middleware/php-debug-bar
To build this middleware you need to injecting inside PhpDebugBarMiddleware
instance DebugBar\JavascriptRenderer
(you can get it from DebugBar\StandardDebugBar
) and add middleware to your middleware runner. Or use default factory.
$debugbar = new DebugBar\StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer('/phpdebugbar');
$middleware = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware($debugbarRenderer);
// OR
$factory = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory();
$middleware = $factory();
$app = new MiddlewareRunner();
$app->add($middleware);
$app->run($request, $response);
You don't need to copy any static assets from phpdebugbar vendor!
Sometimes you want to have control when enable (or not) PHP Debug Bar:
- custom content negotiation,
- allow to debug redirects responses.
We allow you to disable attaching phpdebugbar using X-Enable-Debug-Bar: false
header, cookie or request attribute.
To force enable just send request with X-Enable-Debug-Bar
header, cookie or request attribute with true
value.
You need to register ConfigProvider and pipe provided middleware:
$app->pipe(PhpDebugBarMiddleware::class);
For more follow Zend Expressive documentation.
Add existing factory to container:
$container['debugbar_middleware'] = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory();
and add middleware from container to app:
$app->add($app->getContainer()->get('debugbar_middleware'));
Put array with configuration into config
service in your container:
return [
'phpmiddleware' => [
'phpdebugbar' => [
'javascript_renderer' => [
'base_url' => '/phpdebugbar',
],
'collectors' => [
DebugBar\DataCollector\ConfigCollector::class, // Service names of collectors
],
'storage' => null, // Service name of storage
],
],
];
Middleware tested on:
And any other modern framework supported middlewares and PSR-7.