No frills PSR-7 request handler based on PSR-15 specification.

2.0 2020-04-23 06:54 UTC

This package is auto-updated.

Last update: 2021-04-23 08:57:25 UTC


README

No frills PSR-7 request handler based on PSR-15 specification.

Vidyut: विद्युत् (Electricity)

Build status Code Coverage Latest Version Downloads PHP Version License

SensioLabsInsight

Install

composer require vaibhavpandeyvpz/vidyut

# You will also need a PSR-7 implementation
composer require vaibhavpandeyvpz/sandesh

Usage

<?php

/**
 * @desc Middleware can be an instance of Psr\Http\Server\MiddlewareInterface or a callable with similar signature.
 */
$pipeline = new Vidyut\Pipeline();

$pipeline->pipe(function ($request, $delegate) {
    if ($request->getUri()->getPath() === '/login') {
        $response =  (new Sandesh\ResponseFactory())->createResponse();
        $response->getBody()->write('Login');
        return $response;
    }
    return $delegate->process($request);
});

$pipeline->pipe(function ($request, $delegate) {
    if ($request->getUri()->getPath() === '/logout') {
        $response =  (new Sandesh\ResponseFactory())->createResponse();
        $response->getBody()->write('Logout');
        return $response;
    }
    return $delegate->process($request);
});

$pipeline->pipe(function () {
    $response =  (new Sandesh\ResponseFactory())->createResponse();
    $response->getBody()->write('Page could not be found.');
    return $response->withStatus(404);
});

$request = (new Sandesh\ServerRequestFactory())
    ->createServerRequest($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER);
$response = $pipeline->handle($request);

License

See LICENSE.md file.