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
Size: 83
Language: PHP
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Common utilities used by the middlewares' packages:
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();
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());
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.