0 follower

Final Class Yiisoft\Yii\Http\Application

InheritanceYiisoft\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

Hide inherited 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

Hide inherited methods

__construct() public method

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()
) {
}

            
afterEmit() public method

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));
}

            
handle() public method

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));
    }
}

            
shutdown() public method

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());
}

            
start() public method

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());
}