/**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param callable $next
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if (headers_sent() === false || $this->checkOutputStart === false) {
         $this->emitter->emit($response);
     }
     $next();
 }
示例#2
0
 /**
  * @param Body $body
  * @param Request $request
  * @param HeadersSet $headerSet
  * @param EmitterInterface $emitterInterface
  * @return int
  */
 public static function sendBodyResponse(Body $body, Request $request, HeadersSet $headerSet, EmitterInterface $emitterInterface)
 {
     $response = new TierResponse($request, $headerSet, $body);
     $emitterInterface->emit($response);
     flush();
     return \Tier\TierApp::PROCESS_CONTINUE;
 }
 public function respond($data, $status = 200, array $headers = [])
 {
     $response = new JsonResponse($data, $status, $headers);
     foreach ($this->responseModifiers as $modifier) {
         $response = $modifier->modify($response);
     }
     $this->emitter->emit($response);
 }
示例#4
0
 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param callable|null $next
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
 {
     // Checks if or where headers not have been sent
     if (headers_sent() === false) {
         // Execute code before calling the next middleware
         $this->emitter->emit($response);
     }
     $next($request, $response);
 }
示例#5
0
 /** @inheritdoc */
 public function dispatch()
 {
     $runner = new Runner($this->buildQueue(), function ($file) {
         return $this->resolve($file);
     });
     $output = $runner($this->request, $this->response);
     $this->emitter->emit($output);
     exit;
 }
示例#6
0
文件: HttpCore.php 项目: vvval/spiral
 /**
  * Dispatch response to client.
  *
  * @param ResponseInterface $response
  * @return null Specifically.
  */
 public function dispatch(ResponseInterface $response)
 {
     if (empty($this->emitter)) {
         $this->emitter = new Emitter();
     }
     $this->emitter->emit($response, ob_get_level());
     return null;
 }
示例#7
0
 /**
  * @inheritdoc
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     if ($this->errorHandler) {
         $out = $this->encapsulateErrorHandler($this->errorHandler, $out);
     }
     $response = parent::__invoke($request, $response, $out);
     $this->emitter->emit($response);
 }
示例#8
0
 /**
  * Retrieve an emitter to use during run().
  *
  * If none was registered during instantiation, this will lazy-load an
  * EmitterStack composing an SapiEmitter instance.
  *
  * @return EmitterInterface
  */
 public function getEmitter()
 {
     if (!$this->emitter) {
         $this->emitter = new Emitter\EmitterStack();
         $this->emitter->push(new SapiEmitter());
     }
     return $this->emitter;
 }
示例#9
0
 /**
  * @inheritdoc
  */
 public function handleResponse(ResponseInterface $response)
 {
     $this->sapiEmitter->emit($response);
 }
示例#10
0
 /**
  * Handle the global incoming request and sends the response.
  *
  * @see handle() to handle an HTTP request and not write the response to the output.
  */
 public function run(ServerRequestInterface $request = null)
 {
     $request = $request ?: ServerRequestFactory::fromGlobals();
     $response = $this->handle($request);
     $this->responseEmitter->emit($response);
 }
 /**
  * @param \Psr\Http\Message\ServerRequestInterface $request
  * @param \Psr\Http\Message\ResponseInterface $response
  * @param \WoohooLabs\Harmony\Harmony $next
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Harmony $next)
 {
     $this->emitter->emit($response);
     $next();
 }
示例#12
0
 /**
  * Runs the application by invoking itself with the request and response, and emitting the returned response.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  */
 public function run(ServerRequestInterface $request, ResponseInterface $response)
 {
     $response = parent::__invoke($request, $response);
     $this->emitter->emit($response);
 }
示例#13
0
 /**
  * @param string $code
  * @param string $body
  */
 public function getErrorResponse($code, $body = '{}')
 {
     $this->response->getBody()->write($body);
     return $this->emitter->emit($this->response->withStatus($code));
 }