PHP code example of bitexpert / prophiler-psr7-middleware

1. Go to this page and download the library: Download bitexpert/prophiler-psr7-middleware library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bitexpert / prophiler-psr7-middleware example snippets


    $prophiler = new \Fabfuel\Prophiler\Profiler();
    $toolbar = new \Fabfuel\Prophiler\Toolbar($prophiler);

    $request = \Zend\Diactoros\ServerRequestFactory::fromGlobals();
    $response = \Zend\Diactoros\Response();

    $app = new \Zend\Stratigility\MiddlewarePipe();

    $app->pipe(new \bitExpert\Http\Middleware\Psr7\Prophiler\ProphilerMiddleware($toolbar));

    $response = $app($request, $response);

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

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

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);
    }
}

$app->pipe(ErrorHandler::class);

$debug = $app->getContainer()->get('config')['debug'] ?? false;
if ($debug) {
   $prophiler  = new \Fabfuel\Prophiler\Profiler();
   $toolbar    = new \Fabfuel\Prophiler\Toolbar($prophiler);
   $middleware = new \bitExpert\Http\Middleware\Psr7\Prophiler\ProphilerMiddleware($toolbar);
   $app->pipe($middleware);
}

$app->pipe(ServerUrlMiddleware::class);

$profiler->start('\My\Class::doSomeOtherThing', ['additional' => 'information'], 'My Component');

// here be your custom code

$profiler->stop();