2017 © Pedro Peláez
 

library php-debug-bar

PHP Debug Bar PSR-15 middleware with PSR-7

image

php-middleware/php-debug-bar

PHP Debug Bar PSR-15 middleware with PSR-7

  • Thursday, April 26, 2018
  • by snapshotpl
  • Repository
  • 2 Watchers
  • 38 Stars
  • 16,386 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 8 Forks
  • 0 Open issues
  • 13 Versions
  • 16 % Grown

The README.md

phpdebugbar middleware Build Status

PHP Debug Bar as framework-agnostic PSR-15 middleware with PSR-7 messages created by PSR-17 message factories. Also provides PSR-11 container invokable factories., (*1)

Framework-agnostic way to attach PHP Debug Bar to your response (html or non-html!)., (*2)

Installation

composer require --dev php-middleware/php-debug-bar

To build middleware you need to inject DebugBar\JavascriptRenderer (you can get it from DebugBar\StandardDebugBar) inside PhpDebugBarMiddleware and add it into your middleware runner:, (*3)

$debugbar = new DebugBar\StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer('/phpdebugbar');
$middleware = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware($debugbarRenderer, $psr17ResponseFactory, $psr17StreamFactory);

// or use provided factory
$factory = new PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory();
$middleware = $factory($psr11Container);

$app = new MiddlewareRunner();
$app->add($middleware);
$app->run($request, $response);

You don't need to copy any static assets from phpdebugbar vendor!, (*4)

How to force disable or enable PHP Debug Bar?

Sometimes you want to have control when enable or disable PHP Debug Bar: * custom content negotiation, * allow debug redirects responses., (*5)

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., (*6)

PSR-17

This package isn't require any PSR-7 implementation - you need to provide it by own. Middleware require ResponseFactory and StreamFactory interfaces. List of existing interfaces., (*7)

... and PSR-11

If you use provided PSR-11 factories, then your container must have services registered as PSR-17 interface's name. Example for laminas-diactoros implementation and Pimple:, (*8)

$container[Psr\Http\Message\ResponseInterface::class] = new Laminas\Diactoros\ResponseFactory();
$container[Psr\Http\Message\StreamFactoryInterface::class] = new Laminas\Diactoros\StreamFactory();

How to install on Mezzio?

You need to register PhpMiddleware\PhpDebugBar\ConfigProvider and pipe provided middleware:, (*9)

$app->pipe(\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class);

For more - follow Mezzio documentation., (*10)

How to install on Slim 3?

Register factories in container:, (*11)

foreach (ConfigProvider::getConfig()['dependencies']['factories'] as $key => $factory) {
    $container[$key] = new $factory();
}

and add middleware from container to app:, (*12)

$app->add(
    $app->getContainer()->get(\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class)
);

How to configure using existing factories?

Put array with a configuration into PhpMiddleware\PhpDebugBar\ConfigProvider service in your container:, (*13)

return [
    'phpmiddleware' => [
        'phpdebugbar' => [
            'javascript_renderer' => [
                'base_url' => '/phpdebugbar',
            ],
            'collectors' => [
                DebugBar\DataCollector\ConfigCollector::class, // Service names of collectors
            ],
            'storage' => null, // Service name of storage
        ],
    ],
];

You can override existing configuration by merge default configuration with your own (example):, (*14)

return array_merge(PhpMiddleware\PhpDebugBar\ConfigProvider::getConfig(), $myOverritenConfig);

It's just works with any modern php framework!

Middleware tested on: * Mezzio * Slim 3.x, (*15)

And any other modern framework supported PSR-17 middlewares and PSR-7., (*16)

The Versions

09/01 2016

1.1.0

1.1.0.0

PHP Debug bar middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

debug middleware psr psr-7

07/01 2016

1.0.1

1.0.1.0

PHP Debug bar middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

debug middleware psr psr-7

31/08 2015

1.0.0

1.0.0.0

PHP Debug bar middleware with PSR-7

  Sources   Download

The Requires

 

The Development Requires

debug middleware psr psr-7