Zend\Diactoros\Response\SapiEmitter::emit PHP Method

emit() public method

Emits the status line and headers via the header() function, and the body content via the output buffer.
public emit ( Psr\Http\Message\ResponseInterface $response, null | integer $maxBufferLevel = null )
$response Psr\Http\Message\ResponseInterface
$maxBufferLevel null | integer Maximum output buffering level to unwrap.
    public function emit(ResponseInterface $response, $maxBufferLevel = null)
    {
        if (headers_sent()) {
            throw new RuntimeException('Unable to emit response; headers already sent');
        }
        $response = $this->injectContentLength($response);
        $this->emitStatusLine($response);
        $this->emitHeaders($response);
        $this->flush($maxBufferLevel);
        $this->emitBody($response);
    }

Usage Example

 /**
  * Invocation
  *
  * @param ServerRequestInterface $request Request
  * @param ResponseInterface $response Response
  * @param callable $next Next Middleware
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $response = $next($request, $response);
     $emitter = new SapiEmitter();
     $emitter->emit($response);
     return $response;
 }
All Usage Examples Of Zend\Diactoros\Response\SapiEmitter::emit
SapiEmitter