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 Yiisoft\Yii\Http\Event\AfterEmit to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
| handle() | Handles a request by passing it through the middleware stack MiddlewareDispatcher and returns a response. | Yiisoft\Yii\Http\Application |
| shutdown() | Dispatches an event Yiisoft\Yii\Http\Event\ApplicationShutdown to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
| start() | Dispatches an event Yiisoft\Yii\Http\Event\ApplicationStartup to all relevant listeners for processing. | Yiisoft\Yii\Http\Application |
Method Details
| public __construct( \Yiisoft\Middleware\Dispatcher\MiddlewareDispatcher $dispatcher, \Psr\EventDispatcher\EventDispatcherInterface|null $eventDispatcher = null, \Psr\Http\Server\RequestHandlerInterface $fallbackHandler = new UnhandledRequestHandler() ): mixed | ||
| $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 Yiisoft\Yii\Http\Event\AfterEmit to all relevant listeners for processing.
| public afterEmit( \Psr\Http\Message\ResponseInterface|null $response ): void | ||
| $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 MiddlewareDispatcher and returns a response.
Dispatches Yiisoft\Yii\Http\Event\BeforeRequest and Yiisoft\Yii\Http\Event\AfterRequest events to all relevant listeners for processing.
| public handle( \Psr\Http\Message\ServerRequestInterface $request ): \Psr\Http\Message\ResponseInterface | ||
| $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 Yiisoft\Yii\Http\Event\ApplicationShutdown to all relevant listeners for processing.
| public shutdown( ): void |
public function shutdown(): void
{
$this->eventDispatcher?->dispatch(new ApplicationShutdown());
}
Dispatches an event Yiisoft\Yii\Http\Event\ApplicationStartup to all relevant listeners for processing.
| public start( ): void |
public function start(): void
{
$this->eventDispatcher?->dispatch(new ApplicationStartup());
}
Signup or Login in order to comment.