PHP code example of ztsu / reacon
1. Go to this page and download the library: Download ztsu/reacon 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/ */
ztsu / reacon example snippets
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class CreateRequestMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
return new Zend\Diactoros\Response();
}
}
class HelloMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$response = $handler->handle($request);
$response->getBody()->write("Hello, World!");
return $response;
}
}
$reacon = new Ztsu\Reacon\Reacon(
new HelloMiddleware(),
new CreateRequestMiddleware()
);
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals();
$response = $reacon->handle($request);
(new Zend\Diactoros\Response\SapiEmitter)->emit($response);