1. Go to this page and download the library: Download buzzingpixel/corbomite-http 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/ */
buzzingpixel / corbomite-http example snippets
declare(strict_types=1);
use corbomite\di\Di;
use corbomite\http\Kernel as HttpKernel;
declare(strict_types=1);
namespace src\app\http;
use Throwable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use some\name\space\RenderErrorPageAction;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use corbomite\http\exceptions\Http404Exception;
class ErrorPages implements MiddlewareInterface
{
private $renderErrorPage;
public function __construct(RenderErrorPageAction $renderErrorPage)
{
$this->renderErrorPage = $renderErrorPage;
}
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
try {
return $handler->handle($request);
} catch (Throwable $e) {
$code = 500;
if ($e instanceof Http404Exception ||
$e->getPrevious() instanceof Http404Exception
) {
$code = 404;
}
return ($this->renderErrorPage)($code);
}
}
}