Final Class Yiisoft\Yii\Http\Application
| Inheritance | Yiisoft\Yii\Http\Application |
|---|
Application is the entry point for an HTTP application.
For more details and usage information on Application, see the guide article on applications:
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Http\Application | |
| afterEmit() | Dispatches an event {@see AfterEmit} to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
| handle() | Handles a request by passing it through the middleware stack {@see MiddlewareDispatcher} and returns a response. | Yiisoft\Yii\Http\Application |
| shutdown() | Dispatches an event {@see ApplicationShutdown} to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
| start() | Dispatches an event {@see ApplicationStartup} to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
Method Details
| public mixed __construct ( \Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher $dispatcher, \Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher = null, \Psr\Http\Server\RequestHandlerInterface $fallbackHandler = new UnhandledRequestHandler() ) | ||
| $dispatcher | \Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher |
The middleware dispatcher instance. |
| $eventDispatcher | \Psr\EventDispatcher\EventDispatcherInterface|null |
The event dispatcher instance (optional). |
| $fallbackHandler | \Psr\Http\Server\RequestHandlerInterface |
The fallback handler that will be called if no response was returned during request handling. |
public function __construct(
private readonly MiddlewareDispatcher $dispatcher,
private readonly EventDispatcherInterface|null $eventDispatcher = null,
private readonly RequestHandlerInterface $fallbackHandler = new UnhandledRequestHandler()
) {
}
Dispatches an event {@see AfterEmit} to all relevant listeners for processing.
| public void afterEmit ( \Psr\Http\Message\ResponseInterface|null $response ) | ||
| $response | \Psr\Http\Message\ResponseInterface|null |
Response instance or null if response generation failed due to an error. |
public function afterEmit(?ResponseInterface $response): void
{
$this->eventDispatcher?->dispatch(new AfterEmit($response));
}
Handles a request by passing it through the middleware stack {@see MiddlewareDispatcher} and returns a response.
Dispatches {@see \Yiisoft\Yii\Http\Event\BeforeRequest} and {@see \Yiisoft\Yii\Http\Event\AfterRequest} events to all relevant listeners for processing.
| public \Psr\Http\Message\ResponseInterface handle ( \Psr\Http\Message\ServerRequestInterface $request ) | ||
| $request | \Psr\Http\Message\ServerRequestInterface |
The request instance to handle. |
| return | \Psr\Http\Message\ResponseInterface |
The resulting instance of the response. |
|---|---|---|
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->eventDispatcher?->dispatch(new BeforeRequest($request));
try {
return $response = $this->dispatcher->dispatch($request, $this->fallbackHandler);
} finally {
$this->eventDispatcher?->dispatch(new AfterRequest($response ?? null));
}
}
Dispatches an event {@see ApplicationShutdown} to all relevant listeners for processing.
| public void shutdown ( ) |
public function shutdown(): void
{
$this->eventDispatcher?->dispatch(new ApplicationShutdown());
}
Signup or Login in order to comment.