PHP code example of legatus / http-errors
1. Go to this page and download the library: Download legatus/http-errors 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/ */
legatus / http-errors example snippets
declare(strict_types=1);
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface as Next;
/**
* Class SomeAuthorizationMiddleware
*/
class SomeAuthorizationMiddleware implements MiddlewareInterface
{
public function process(Request $request, Next $next): Response
{
if (!$this->isAuthorized($request)) {
// Throw the exception and handle it in an upstream middleware
throw new Legatus\Http\Unauthorized($request);
}
return $next->handle($request);
}
}