toString() public static method

Serialize a request message to a string.
public static toString ( Psr\Http\Message\RequestInterface $request ) : string
$request Psr\Http\Message\RequestInterface
return string
Example #1
0
 private function generateRequestLog(Request $request, Response $response)
 {
     if ($this->options['full']) {
         return RequestSerializer::toString($request);
     }
     $msg = sprintf("%s %s", $request->getMethod(), $request->getRequestTarget());
     if ($request->hasHeader('X-Request-Id')) {
         $msg .= ' RequestId: ' . $request->getHeader('X-Request-Id')[0];
     } elseif ($response->hasHeader('X-Request-Id')) {
         $msg .= ' RequestId: ' . $response->getHeader('X-Request-Id')[0];
     }
     return $msg;
 }
 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);
 }
Example #3
0
 public function serialize()
 {
     $data = ['requestData' => $this->requestData];
     if ($request = $this->getRequest()) {
         $data['request'] = \Zend\Diactoros\Request\Serializer::toString($request);
     }
     if ($response = $this->getResponse()) {
         $data['response'] = \Zend\Diactoros\Response\Serializer::toString($response);
     }
     return serialize($data);
 }
 protected function getContentToLog(ServerRequestInterface $request, ResponseInterface $response, callable $out = null)
 {
     return Serializer::toString($request);
 }
Example #5
0
 /**
  * Send request
  *
  * @param Socket $socket
  * @param RequestInterface $request
  * @param callable $onSuccess
  * @param callable $onFailure
  *
  * @return boolean
  */
 protected function sendRequest(Socket $socket, RequestInterface $request, $onSuccess, $onFailure)
 {
     $data = trim(RequestSerializer::toString($request)) . "\r\n\r\n";
     try {
         $bytes = $socket->sendTo($data, 0, sprintf('%s:%s', self::MULTICAST_ADDRESS, self::MULTICAST_PORT));
     } catch (SocketException $exception) {
         return $onFailure($socket, $exception);
     }
     return $onSuccess($socket, $bytes);
 }
 public function format(ServerRequestInterface $request, ResponseInterface $response)
 {
     return Serializer::toString($request);
 }