Using Prophiler with zend-expressive

Using Prophiler with zend-expressive

A few weeks back we released a Prophiler PSR-7 middleware which we created during a hack session on Adroit, our little, clever ADR middleware implementation. I`d like to show you how to integrate the Prophiler middleware in a zend-expressive application. As it turns out this is super simple.

At first I had to register a pre_routing middleware in config/autoload/middleware-pipeline.local.php:

return [
    'middleware_pipeline' => [[
        'middleware' => bitExpert\Http\Middleware\Psr7\
            Prophiler\ProphilerMiddleware::class,
        'priority' => 11000,
    ]]
];


In addition to that, I had to add a factory definition to config/autoload/dependencies.global.php:

return [
    'dependencies' => [
        'factories' => [
            bitExpert\Http\Middleware\Psr7\Prophiler\
                ProphilerMiddleware::class => 
                App\Middleware\ProphilerFactory::class
        ]
    ]
];


The \App\Middleware\ProphilerFactory implementation looks like this:

namespace App\Middleware;

use Interop\Container\ContainerInterface;
use Fabfuel\Prophiler\Profiler;
use Fabfuel\Prophiler\Toolbar;
use bitExpert\Http\Middleware\Psr7\Prophiler\ProphilerMiddleware;

class ProphilerFactory
{
    public function __invoke(ContainerInterface $container)
    {
        $prophiler = new Profiler();
        $toolbar = new Toolbar($prophiler);
        return new ProphilerMiddleware($toolbar);
    }
}


When running your zend-expressive application now, you should be able to the Prophiler toolbar on top of the page.


Update: Updated the code snippets as pointed out by Roma Kosolapov.


Eintrag von Stephan Hochdörfer am 14.12.2015

Tags: Zend, Expressive, Prophiler

Diese Webseite verwendet Cookies, um die Bedienfreundlichkeit zu erhöhen. Mit der Nutzung unserer Webseite wird das Einverständnis erklärt, dass wir Cookies verwenden. Weitere Informationen.