https://github.com/php-pm/php-pm-psr7
A PSR-7 middleware bridge for PHP-PM
https://github.com/php-pm/php-pm-psr7
Last synced: about 1 month ago
JSON representation
A PSR-7 middleware bridge for PHP-PM
- Host: GitHub
- URL: https://github.com/php-pm/php-pm-psr7
- Owner: php-pm
- Archived: true
- Created: 2016-04-18T23:44:27.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-30T09:01:23.000Z (about 8 years ago)
- Last Synced: 2023-08-15T11:29:43.206Z (over 2 years ago)
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 27
- Watchers: 6
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
**[OBSOLETE] PSR-7 compatibility is now built into [php-pm](https://github.com/php-pm/php-pm) directly.**
# PHP-PM PSR-7 Adapter
[PSR-7](http://www.php-fig.org/psr/psr-7/) adapter for use of PSR-7 middleware applications with PHP-PM.
See https://github.com/php-pm/php-pm.
## Setup
```
composer require php-pm/psr7-adapter
```
## Usage
PPM bootstraps your application once, and then passes all incoming requests to this instance.
This instance needs to be a PSR-7 compatible interface, which means it needs to implement the following interface:
```php
public function __invoke($request, $response, $next = null)
```
So, to be compatible with this adapter, you need to implement a class that, when instantiated, sets up your application, and implements the `__invoke` method as described above.
For example, if you use Zend's [Stratigility library](https://github.com/zendframework/zend-stratigility), your bootstrapper could look like this:
```php
namespace Your\App;
use Zend\Stratigility\MiddlewarePipe;
class Middleware
{
protected $pipe;
public function __construct()
{
// Set up the application
$this->pipe = new MiddlewarePipe;
$this->pipe->pipe(new MyFirstMiddleware);
$this->pipe->pipe(new MySecondMiddleware);
$this->pipe->pipe(new MyThirdMiddleware);
}
public function __invoke($request, $response, $next = null)
{
$middleware = $this->pipe;
return $middleware($request, $response, $next);
}
}
```
### Starting the server
When starting PPM, pass your middleware as the bootstrapper:
```
vendor/bin/ppm start --bridge=PHPPM\\Psr7\\Psr7Bridge --bootstrap=Your\\App\\Middleware
```
Alternatively, first configure PPM to use these options by default, and then start it directly:
```
vendor/bin/ppm config --bridge=PHPPM\\Psr7\\Psr7Bridge --bootstrap=Your\\App\\Middleware
vendor/bin/ppm start
```