cornfield-io/middlewares

PSR-15: HTTP Server Request Handlers implementation.

2.1.0 2019-03-31 07:54 UTC

This package is auto-updated.

Last update: 2024-04-29 03:18:41 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score

PSR-15: HTTP Server Request Handlers implementation.

Install

Via Composer

$ composer require cornfield-io/middlewares

Requirements

  • You need PHP >= 7.2.0 to use Cornfield\Middlewares but the latest stable version of PHP is recommended.

  • An implementation of PSR-7 (we recommend the Zend Diactoros project).

  • Optionally, you could also install a PSR-11 dependency injection container (we recommend the PHP-DI project).

Throughout this documentation, we will assume that you are using the packages above. If you want, you can still install other implementations of PSR-7 or PSR-11.

Usage

All middlewares added must implement Psr\Http\Server\MiddlewareInterface.

<?php

use Cornfield\Middlewares\Middlewares;
use Zend\Diactoros\ServerRequestFactory;

$middlewares = new Middlewares();
$request = ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);

// Prepend one or more middlewares
$middlewares->unshift('Middleware1');
$middlewares->unshift([Middleware2, 'Middleware3']);

// Push one or more middlewares
$middlewares->push(Middleware4);
$middlewares->push(['Middleware5', Middleware6]);

// Process the request
$response = $middlewares->handle($request);

ContainerInterface

Cornfield\Middlewares supports Psr\Container\ContainerInterface

<?php

use Cornfield\Middlewares\Middlewares;

$middlewares = new Middlewares(/* ContainerInterface */);

// Or

$middlewares->setContainer(/* ContainerInterface */);

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Development

$ composer dev

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.