1. Go to this page and download the library: Download stefna/http-runner 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/ */
stefna / http-runner example snippets
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Stefna\Http\Middleware\ContainerMiddlewareResolver;
use Stefna\Http\Middleware\NullMiddlewareResolver;
use Stefna\Http\Middleware\Runner;
use Stefna\Http\Middleware\SimpleMiddlewarePipeline;
use Stefna\Http\Request\ServerRequestMarshal;
use Stefna\Http\ResponseHandler\HttpResponseHandler;
/** @var ContainerInterface $container */
/** @var ResponseFactoryInterface $responseFactory */
$middlewares = new SimpleMiddlewarePipeline(
new CrashMiddleware(),
new SessionMiddleware(),
new RouterMiddleware(),
new RouteDispatchMiddleware(),
);
// no resolving of middlewares all middlewares need to be instantiated earlier
$middlewareResolver = new NullMiddlewareResolver();
// or if middleware is a string look in container for it and lazy create it when needed
$middlewareResolver = new ContainerMiddlewareResolver($container);
$runner = new Runner(
$middlewares,
$responseFactory,
$middlewareResolver,
);
// boot request
/** @var ServerRequestInterface $request */
$request = (new ServerRequestMarshal())->marshal($_SERVER);
// dispatch middlewares and get a response back
$response = $runner->handle($request);
// send response
(new HttpResponseHandler())->handle($response);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.