PHP code example of biurad / http-galaxy
1. Go to this page and download the library: Download biurad/http-galaxy 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/ */
biurad / http-galaxy example snippets
use Biurad\Http\Factory\Psr17Factory;
use Biurad\Http\Middlewares\PrepareResponseMiddleware;
use Biurad\Http\Response;
use Laminas\Stratigility\Middleware\CallableMiddlewareDecorator;
use Laminas\Stratigility\MiddlewarePipe;
use Psr\Http\Message\{ResponseInterface, ServerRequestInterface};
use Psr\Http\Server\RequestHandlerInterface;
// Create a PSR-7 Request
$request = Psr17Factory::fromGlobalRequest();
// Create a PSR-15 Request Handler
$dispatcher = new MiddlewarePipe();
$dispatcher->pipe(new PrepareResponseMiddleware());
$dispatcher->pipe(
new CallableMiddlewareDecorator(
function (ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
// Apply middleware logic here
return $handler->handle($request);
}
)
);
// A request handler handling application's logic
$handler = new \App\MyRequestHandler();
// Process the request handler and middleware(s)
$response = $dispatcher->process($request, $handler);
\assert($response instanceof Response);
// Send the response to the client from symfony's response object
$response->getResponse()->send();