You are here

public function Server::listen in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/Server.php \Zend\Diactoros\Server::listen()

"Listen" to an incoming request

If provided a $finalHandler, that callable will be used for incomplete requests.

Output buffering is enabled prior to invoking the attached callback; any output buffered will be sent prior to any response body content.

Parameters

null|callable $finalHandler:

File

vendor/zendframework/zend-diactoros/src/Server.php, line 159

Class

Server
"Serve" incoming HTTP requests

Namespace

Zend\Diactoros

Code

public function listen(callable $finalHandler = null) {
  $callback = $this->callback;
  ob_start();
  $bufferLevel = ob_get_level();
  $response = $callback($this->request, $this->response, $finalHandler);
  if (!$response instanceof ResponseInterface) {
    $response = $this->response;
  }
  $this
    ->getEmitter()
    ->emit($response, $bufferLevel);
}