PHP code example of yiisoft / yii-http
1. Go to this page and download the library: Download yiisoft/yii-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/ */
yiisoft / yii-http example snippets
use Yiisoft\Yii\Http\Application;
use Yiisoft\Yii\Http\Handler\NotFoundHandler;
use Yiisoft\Yii\Http\Handler\ThrowableHandler;
/**
* @var Psr\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @var Psr\Http\Message\ResponseFactoryInterface $responseFactory
* @var Psr\Http\Message\ServerRequestInterface $request
* @var Yiisoft\ErrorHandler\Middleware\ErrorCatcher $errorCatcher
* @var Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher $dispatcher
*/
$fallbackHandler = new NotFoundHandler($responseFactory);
$application = new Application($dispatcher, $eventDispatcher, $fallbackHandler);
try {
$application->start();
$response = $application->handle($request);
// Emit a response.
} catch (Throwable $throwable) {
$handler = new ThrowableHandler($throwable);
$response = $errorCatcher->process($request, $handler);
// Emit a response with information about the error.
} finally {
$application->afterEmit($response ?? null);
$application->shutdown();
}