middlewares/utils

Name: utils

Owner: Middlewares

Description: Common utils used by PSR-15 middlewares

Created: 2016-09-30 17:19:52.0

Updated: 2018-04-25 08:12:38.0

Pushed: 2018-01-24 18:49:23.0

Homepage:

Size: 83

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

middlewares/utils

Latest Version on Packagist Software License Build Status Quality Score Total Downloads SensioLabs Insight

Common utilities used by the middlewares' packages:

Factory

Used to create psr-7 instances of ServerRequestInterface, ResponseInterface, StreamInterface and UriInterface. Detects automatically Diactoros, Guzzle and Slim but you can register a different factory using the http-interop/http-factory interface.

Middlewares\Utils\Factory;

uest = Factory::createServerRequest();
ponse = Factory::createResponse();
eam = Factory::createStream();
 = Factory::createUri('http://example.com');

gister other factory
ory::setResponseFactory(new FooResponseFactory());

Response = Factory::createResponse();
Dispatcher

Minimalist PSR-15 compatible dispatcher. Used for testing purposes.

Middlewares\Utils\Factory;
Middlewares\Utils\Dispatcher;

patcher = new Dispatcher([
new Middleware1(),
new Middleware2(),
new Middleware3(),
function ($request, $next) {
    $response = $next->handle($request);
    return $response->withHeader('X-Foo', 'Bar');
}


ponse = $dispatcher->dispatch(Factory::createServerRequest());
CallableHandler

To resolve and execute a callable. It can be used as a middleware, server request handler or a callable:

Middlewares\Utils\CallableHandler;

lable = new CallableHandler(function () {
return 'Hello world';


ponse = $callable();

 $response->getBody(); //Hello world

Please see CHANGELOG for more information about recent changes and CONTRIBUTING for contributing details.

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


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.