Zend\Diactoros\Server::setEmitter PHP Method

setEmitter() public method

Set alternate response emitter to use.
public setEmitter ( Zend\Diactoros\Response\EmitterInterface $emitter )
$emitter Zend\Diactoros\Response\EmitterInterface
    public function setEmitter(Response\EmitterInterface $emitter)
    {
        $this->emitter = $emitter;
    }

Usage Example

Example #1
0
 /**
  * "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.
  *
  * @param null|callable $finalHandler
  */
 private function traverse_middleware_pipeline($finalHandler = NULL)
 {
     $pipeline = $this->kernel->middleware();
     $emitter = new SapiEmitter();
     $this->server->setEmitter($emitter);
     ob_start();
     $bufferLevel = ob_get_level();
     # the work is done here
     $response = $pipeline($this->server->{'request'}, $this->server->{'response'}, $finalHandler);
     if (!$response instanceof ResponseInterface) {
         $response = $this->server->{'response'};
     }
     $emitter->emit($response, $bufferLevel);
 }