PHP code example of vaibhavpandeyvpz / vidyut

1. Go to this page and download the library: Download vaibhavpandeyvpz/vidyut library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vaibhavpandeyvpz / vidyut example snippets




/**
 * @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);