getOutput() public static method

Return the output buffer.
public static getOutput ( integer $level ) : string
$level integer
return string
コード例 #1
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     ob_start();
     $level = ob_get_level();
     $method = Run::EXCEPTION_HANDLER;
     $whoops = $this->getWhoopsInstance($request);
     $whoops->allowQuit(false);
     $whoops->writeToOutput(false);
     $whoops->sendHttpCode(false);
     //Catch errors means register whoops globally
     if ($this->catchErrors) {
         $whoops->register();
     }
     try {
         $response = $next($request, $response);
     } catch (\Throwable $exception) {
         $body = self::createStream($response->getBody());
         $body->write($whoops->{$method}($exception));
         $response = $response->withStatus(500)->withBody($body);
     } catch (\Exception $exception) {
         $body = self::createStream($response->getBody());
         $body->write($whoops->{$method}($exception));
         $response = $response->withStatus(500)->withBody($body);
     } finally {
         Utils\Helpers::getOutput($level);
     }
     if ($this->catchErrors) {
         $whoops->unregister();
     }
     return $response;
 }
コード例 #2
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     ob_start();
     $level = ob_get_level();
     try {
         $response = $next($request, $response);
     } catch (\Exception $exception) {
         if (!$this->catchExceptions) {
             throw $exception;
         }
         $request = Middleware::setAttribute($request, self::KEY, $exception);
         $response = $response->withStatus(500);
     } finally {
         Utils\Helpers::getOutput($level);
     }
     if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
         return $this->executeCallable($this->handler, $request, $response);
     }
     return $response;
 }
コード例 #3
0
 /**
  * Execute the callable.
  *
  * @param mixed             $target
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  *
  * @return ResponseInterface
  */
 private function executeCallable($target, RequestInterface $request, ResponseInterface $response)
 {
     ob_start();
     $level = ob_get_level();
     try {
         $arguments = array_merge([$request, $response], $this->arguments);
         $target = self::getCallable($target, $arguments);
         $return = call_user_func_array($target, $arguments);
         if ($return instanceof ResponseInterface) {
             $response = $return;
             $return = '';
         }
         $return = Utils\Helpers::getOutput($level) . $return;
         $body = $response->getBody();
         if ($return !== '' && $body->isWritable()) {
             $body->write($return);
         }
         return $response;
     } catch (\Exception $exception) {
         Utils\Helpers::getOutput($level);
         throw $exception;
     }
 }
コード例 #4
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     $file = $this->getFilename($request, 'php');
     if (!is_file($file)) {
         if ($this->continueOnError) {
             return $next($request, $response);
         }
         return $response->withStatus(404);
     }
     if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'php') {
         $level = ob_get_level();
         ob_start();
         self::includeFile($file);
         $body = self::createStream();
         $body->write(Utils\Helpers::getOutput($level));
         foreach (headers_list() as $header) {
             list($name, $value) = array_map('trim', explode(':', $header, 2));
             $response = $response->withHeader($name, $value);
         }
         return $response->withBody($body);
     }
     return $next($request, $response);
 }
コード例 #5
0
 /**
  * Execute the middleware.
  *
  * @param ServerRequestInterface $request
  * @param ResponseInterface      $response
  * @param callable               $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     ob_start();
     $level = ob_get_level();
     try {
         $response = $next($request, $response);
     } catch (\Throwable $exception) {
         if (!$this->catchExceptions) {
             throw $exception;
         }
         $request = self::setAttribute($request, self::KEY, $exception);
         $response = $response->withStatus(500);
     } catch (\Exception $exception) {
         if (!$this->catchExceptions) {
             throw $exception;
         }
         $request = self::setAttribute($request, self::KEY, $exception);
         $response = $response->withStatus(500);
     } finally {
         Utils\Helpers::getOutput($level);
     }
     if ($this->isError($response->getStatusCode())) {
         $callable = $this->handler ?: [$this, 'defaultHandler'];
         $body = self::createStream($response->getBody());
         return $this->executeCallable($callable, $request, $response->withBody($body));
     }
     return $response;
 }