Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Merge b9a4b60 into bd141ec
Browse files Browse the repository at this point in the history
  • Loading branch information
shochdoerfer committed May 26, 2017
2 parents bd141ec + b9a4b60 commit 863015d
Showing 1 changed file with 75 additions and 8 deletions.
83 changes: 75 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ middleware is responsible for "adding" the Prophiler Toolbar output to the Respo
[![Dependency Status](https://www.versioneye.com/user/projects/57d9b52c712966004c0191a1/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/57d9b52c712966004c0191a1)
[![Coverage Status](https://coveralls.io/repos/github/bitExpert/prophiler-psr7-middleware/badge.svg?branch=master)](https://coveralls.io/github/bitExpert/prophiler-psr7-middleware?branch=master)

Installation
------------
## Installation

The preferred way of installing `bitexpert/prophiler-psr7-middleware` is through Composer. Simply add
`bitexpert/prophiler-psr7-middleware` as a dependency:
Expand All @@ -16,8 +15,7 @@ The preferred way of installing `bitexpert/prophiler-psr7-middleware` is through
composer.phar require bitexpert/prophiler-psr7-middleware
```

How to use it
-------------
## How to use it

Create Prophiler toolbar:

Expand Down Expand Up @@ -45,10 +43,79 @@ Add the ProphilerMiddleware to the Middleware pipe:
```php
$response = $app($request, $response);
```
To use the ProphilerMiddleware in a [Zend Expressive](https://github.com/zendframework/zend-expressive) application
follow [this guide](https://blog.bitexpert.de/blog/using-prophiler-with-zend-expressive/).

License
-------
## How to configure Prophiler PSR7 Middleware in Expressive

### Expressive 1.x

Register a pre_routing middleware in `config/autoload/middleware-pipeline.local.php`:

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

Add a factory definition to `config/autoload/dependencies.global.php`:

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

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

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

### Expressive 2.x (Programmatic Pipelines)

Adding them in the `config/pipeline.php` file:

```php
$app->pipe(ErrorHandler::class);
//... just after the ErrorHandler::class (must be the first one)

$debug = $app->getContainer()->get('config')['debug'] ?? false;
if ($debug) {
/* example with prophilermiddleware */
$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);
//... the rest of the pipeline
```

## License

The Prophiler PSR7 Middleware is released under the Apache 2.0 license.

0 comments on commit 863015d

Please sign in to comment.