Class Server

Runs an application invoking all the PSR7 middleware and the registered application.

Namespace: Cake\Http

Properties summary

  • $_eventClass protected
    string

    Default class name for new event objects.

  • $_eventManager protected
    \Cake\Event\EventManagerInterface|\Cake\Event\EventManager

    Instance of the Cake\Event\EventManager this object is using to dispatch inner events.

  • $app protected
    \Cake\Core\HttpApplicationInterface
  • $runner protected
    \Cake\Http\Runner

Method Summary

Method Detail

__construct() public

__construct(\Cake\Core\HttpApplicationInterface $app)

Constructor

Parameters

\Cake\Core\HttpApplicationInterface $app

The application to use.

bootstrap() protected

bootstrap()

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.

dispatchEvent() public

dispatchEvent(mixed $name, mixed $data, mixed $subject)

Wrapper for creating and dispatching events.

Returns a dispatched event.

Parameters

string $name

Name of the event.

array|null $data optional

Any value you wish to be transported with this event to it can be read by listeners.

object|null $subject optional

The object that this event applies to ($this by default).

Returns

\Cake\Event\Event

emit() public

emit(\Psr\Http\Message\ResponseInterface $response, \Laminas\Diactoros\Response\EmitterInterface $emitter)

Emit the response using the PHP SAPI.

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to emit

\Laminas\Diactoros\Response\EmitterInterface|null $emitter optional

The emitter to use. When null, a SAPI Stream Emitter will be used.

eventManager() public

eventManager(\Cake\Event\EventManager $events)

Get/set the application's event manager.

If the application does not support events and this method is used as a setter, an exception will be raised.

Parameters

\Cake\Event\EventManager|null $events optional

The event manager to set.

Returns

\Cake\Event\EventManager|$this

getApp() public

getApp()

Get the current application.

Returns

\Cake\Core\HttpApplicationInterface

The application that will be run.

getEventManager() public

getEventManager()

Get the application's event manager or the global one.

Returns

\Cake\Event\EventManager

run() public

run(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response)

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.

Parameters

\Psr\Http\Message\ServerRequestInterface|null $request optional

The request to use or null.

\Psr\Http\Message\ResponseInterface|null $response optional

The response to use or null.

Returns

\Psr\Http\Message\ResponseInterface

Throws

RuntimeException
When the application does not make a response.

setEventManager() public

setEventManager(\Cake\Event\EventManager $events)

Get/set the application's event manager.

If the application does not support events and this method is used as a setter, an exception will be raised.

Parameters

\Cake\Event\EventManager $events

The event manager to set.

Returns

$this

setRunner() public

setRunner(\Cake\Http\Runner $runner)

Set the runner

Parameters

\Cake\Http\Runner $runner

The runner to use.

Returns

$this

Property Detail

$_eventClass protected

Default class name for new event objects.

Type

string

$_eventManager protected

Instance of the Cake\Event\EventManager this object is using to dispatch inner events.

Type

\Cake\Event\EventManagerInterface|\Cake\Event\EventManager

$app protected

Type

\Cake\Core\HttpApplicationInterface

$runner protected

Type

\Cake\Http\Runner

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Http.Server.html