/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Http
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/Http/Server.php (5669B)
app = $app;
$this->runner = $runner ?? new Runner();
}
/**
* Run the request/response through the Application and its middleware.
*
* This will invoke the following methods:
*
* - App->bootstrap() - Perform any bootstrapping logic for your application here.
* - App->middleware() - Attach any application middleware here.
* - Trigger the 'Server.buildMiddleware' event. You can use this to modify the
* from event listeners.
* - Run the middleware queue including the application.
*
* @param \Psr\Http\Message\ServerRequestInterface|null $request The request to use or null.
* @param \Cake\Http\MiddlewareQueue $middlewareQueue MiddlewareQueue or null.
* @return \Psr\Http\Message\ResponseInterface
* @throws \RuntimeException When the application does not make a response.
*/
public function run(
?ServerRequestInterface $request = null,
?MiddlewareQueue $middlewareQueue = null
): ResponseInterface {
$this->bootstrap();
$request = $request ?: ServerRequestFactory::fromGlobals();
$middleware = $this->app->middleware($middlewareQueue ?? new MiddlewareQueue());
if ($this->app instanceof PluginApplicationInterface) {
$middleware = $this->app->pluginMiddleware($middleware);
}
$this->dispatchEvent('Server.buildMiddleware', ['middleware' => $middleware]);
$response = $this->runner->run($middleware, $request, $this->app);
if ($request instanceof ServerRequest) {
$request->getSession()->close();
}
return $response;
}
/**
* Application bootstrap wrapper.
*
* Calls `bootstrap()` and `events()` if application implements `EventApplicationInterface`.
* After the application is bootstrapped and events are attached, plugins are bootstrapped
* and have their events attached.
*
* @return void
*/
protected function bootstrap(): void
{
$this->app->bootstrap();
if ($this->app instanceof PluginApplicationInterface) {
$this->app->pluginBootstrap();
}
}
/**
* Emit the response using the PHP SAPI.
*
* @param \Psr\Http\Message\ResponseInterface $response The response to emit
* @param \Laminas\HttpHandlerRunner\Emitter\EmitterInterface|null $emitter The emitter to use.
* When null, a SAPI Stream Emitter will be used.
* @return void
*/
public function emit(ResponseInterface $response, ?EmitterInterface $emitter = null): void
{
if (!$emitter) {
$emitter = new ResponseEmitter();
}
$emitter->emit($response);
}
/**
* Get the current application.
*
* @return \Cake\Core\HttpApplicationInterface The application that will be run.
*/
public function getApp(): HttpApplicationInterface
{
return $this->app;
}
/**
* Get the application's event manager or the global one.
*
* @return \Cake\Event\EventManagerInterface
*/
public function getEventManager(): EventManagerInterface
{
if ($this->app instanceof EventDispatcherInterface) {
return $this->app->getEventManager();
}
return EventManager::instance();
}
/**
* Set the application's event manager.
*
* If the application does not support events, an exception will be raised.
*
* @param \Cake\Event\EventManagerInterface $eventManager The event manager to set.
* @return $this
* @throws \InvalidArgumentException
*/
public function setEventManager(EventManagerInterface $eventManager)
{
if ($this->app instanceof EventDispatcherInterface) {
$this->app->setEventManager($eventManager);
return $this;
}
throw new InvalidArgumentException('Cannot set the event manager, the application does not support events.');
}
}