Inheritance: extends Zend\Diactoros\AbstractSerializer
コード例 #1
0
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $next
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($staticFile = $this->getStaticFile($request->getUri())) {
         return $staticFile;
     }
     $outResponse = $next($request, $response);
     if (!$this->isHtmlAccepted($request)) {
         return $outResponse;
     }
     $debugBarHead = $this->debugBarRenderer->renderHead();
     $debugBarBody = $this->debugBarRenderer->render();
     if ($this->isHtmlResponse($outResponse)) {
         $body = $outResponse->getBody();
         if (!$body->eof() && $body->isSeekable()) {
             $body->seek(0, SEEK_END);
         }
         $body->write($debugBarHead . $debugBarBody);
         return $outResponse;
     }
     $outResponseBody = Serializer::toString($outResponse);
     $template = '<html><head>%s</head><body><h1>DebugBar</h1><p>Response:</p><pre>%s</pre>%s</body></html>';
     $escapedOutResponseBody = htmlspecialchars($outResponseBody);
     $result = sprintf($template, $debugBarHead, $escapedOutResponseBody, $debugBarBody);
     return new HtmlResponse($result);
 }
コード例 #2
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
 {
     if ($request->getMethod() === 'POST') {
         $parsedBody = $this->parseBody($request->getBody());
         if (is_array($parsedBody) && isset($parsedBody[self::PARAM])) {
             $requestToSimulate = $parsedBody[self::PARAM];
             $deserializedRequest = RequestSerializer::fromString($requestToSimulate);
             $request = new ServerRequest($request->getServerParams(), $request->getUploadedFiles(), $deserializedRequest->getUri(), $deserializedRequest->getMethod(), $deserializedRequest->getBody(), $deserializedRequest->getHeaders());
         }
     }
     $requestAsString = RequestSerializer::toString($request);
     $responseResult = $next($request, $response);
     $responseAsString = ResponseSerializer::toString($responseResult);
     $html = sprintf($this->getHtmlTemplate(), self::PARAM, $requestAsString, $responseAsString);
     return new HtmlResponse($html);
 }
コード例 #3
0
ファイル: HttpLog.php プロジェクト: samsonasik/LosLog
 private function generateResponseLog(Request $request, Response $response)
 {
     if ($this->options['full']) {
         return ResponseSerializer::toString($response);
     }
     $reasonPhrase = $response->getReasonPhrase();
     $msg = sprintf("%s %s", $response->getStatusCode(), $reasonPhrase ? $reasonPhrase : '');
     if ($response->hasHeader('X-Request-Id')) {
         $msg .= ' RequestId: ' . $response->getHeader('X-Request-Id')[0];
     } elseif ($request->hasHeader('X-Request-Id')) {
         $msg .= ' RequestId: ' . $request->getHeader('X-Request-Id')[0];
     }
     if ($response->hasHeader('X-Response-Time')) {
         $msg .= ' ResponseTime: ' . $response->getHeader('X-Response-Time')[0];
     }
     return $msg;
 }
コード例 #4
0
 /**
  * @param ServerRequestInterface $request
  * @param ResponseInterface $response
  * @param callable $out
  *
  * @return ResponseInterface
  */
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     $outResponse = $out($request, $response);
     if (!$this->isHtmlAccepted($request)) {
         return $outResponse;
     }
     $debugBarHead = $this->debugBarRenderer->renderHead();
     $debugBarBody = $this->debugBarRenderer->render();
     if ($this->isHtmlResponse($outResponse)) {
         $outResponse->getBody()->write($debugBarHead . $debugBarBody);
         return $outResponse;
     }
     $outResponseBody = Serializer::toString($outResponse);
     $template = '<html><head>%s</head><body><h1>DebugBar</h1><p>Response:</p><pre>%s</pre>%s</body></html>';
     $escapedOutResponseBody = htmlspecialchars($outResponseBody);
     $result = sprintf($template, $debugBarHead, $escapedOutResponseBody, $debugBarBody);
     return new HtmlResponse($result);
 }
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     $response = $out($request, $response);
     $contentType = $response->getHeaderLine('Content-Type');
     $accept = $request->getHeaderLine('Accept');
     if (!$this->acceptHtml($accept)) {
         return $out($request, $response);
     }
     if (self::HTML_CONTENT_TYPE === $contentType) {
         return $out($request, $response);
     }
     $noneHtmlBody = Serializer::toString($response);
     $escapedBody = htmlspecialchars($noneHtmlBody);
     $html = '<html><head><title>Middleware response debugger</title></head><body><h1>Debug response!</h1><hr><pre>%s</pre><hr></body></html>';
     $htmlBody = sprintf($html, $escapedBody);
     $htmlResponse = new HtmlResponse($htmlBody);
     return $htmlResponse;
 }
コード例 #6
0
ファイル: Verification.php プロジェクト: dpodium/yii2-nexmo
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     $this->requestData = $data['requestData'];
     if (isset($data['request'])) {
         $this->request = \Zend\Diactoros\Request\Serializer::fromString($data['request']);
     }
     if (isset($data['response'])) {
         $this->response = \Zend\Diactoros\Response\Serializer::fromString($data['response']);
     }
 }
コード例 #7
0
ファイル: CgiRunner.php プロジェクト: php-school/php-workshop
 /**
  * @param string $fileName
  * @param RequestInterface $request
  * @param string $type
  * @return ResponseInterface
  */
 private function executePhpFile($fileName, RequestInterface $request, $type)
 {
     $process = $this->getProcess($fileName, $request);
     $process->start();
     $this->eventDispatcher->dispatch(new CgiExecuteEvent(sprintf('cgi.verify.%s.executing', $type), $request));
     $process->wait();
     if (!$process->isSuccessful()) {
         throw CodeExecutionException::fromProcess($process);
     }
     //if no status line, pre-pend 200 OK
     $output = $process->getOutput();
     if (!preg_match('/^HTTP\\/([1-9]\\d*\\.\\d) ([1-5]\\d{2})(\\s+(.+))?\\r\\n/', $output)) {
         $output = "HTTP/1.0 200 OK\r\n" . $output;
     }
     return ResponseSerializer::fromString($output);
 }
コード例 #8
0
 public function format(ServerRequestInterface $request, ResponseInterface $response)
 {
     return Serializer::toString($response);
 }
コード例 #9
0
ファイル: Client.php プロジェクト: gravitymedia/ssdp
 /**
  * Create discover event
  *
  * @param string $message
  *
  * @return DiscoverEvent
  */
 protected function createDiscoverEvent($message)
 {
     $response = ResponseSerializer::fromString($message);
     $event = new DiscoverEvent();
     if ($response->hasHeader('CACHE-CONTROL')) {
         $value = $response->getHeaderLine('CACHE-CONTROL');
         $event->setLifetime(intval(substr($value, strpos($value, '=') + 1)));
     }
     if ($response->hasHeader('DATE')) {
         $event->setDate(new \DateTime($response->getHeaderLine('DATE')));
     }
     if ($response->hasHeader('LOCATION')) {
         $event->setDescriptionUrl(new Uri($response->getHeaderLine('LOCATION')));
     }
     if ($response->hasHeader('SERVER')) {
         $event->setServerString($response->getHeaderLine('SERVER'));
     }
     if ($response->hasHeader('ST')) {
         $event->setSearchTargetString($response->getHeaderLine('ST'));
     }
     if ($response->hasHeader('USN')) {
         $event->setUniqueServiceNameString($response->getHeaderLine('USN'));
     }
     return $event;
 }
コード例 #10
0
 protected function getContentToLog(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     return Serializer::toString($response);
 }