VCR\Response::fromArray PHP Method

fromArray() public static method

Creates a new Response from a specified array.
public static fromArray ( array $response ) : Response
$response array Array representation of a Response.
return Response A new Response from a specified array
    public static function fromArray(array $response)
    {
        $body = isset($response['body']) ? $response['body'] : null;
        $gzip = isset($response['headers']['Content-Type']) && strpos($response['headers']['Content-Type'], 'application/x-gzip') !== false;
        $binary = isset($response['headers']['Content-Transfer-Encoding']) && $response['headers']['Content-Transfer-Encoding'] == 'binary';
        // Base64 decode when binary
        if ($gzip || $binary) {
            $body = base64_decode($response['body']);
        }
        return new static(isset($response['status']) ? $response['status'] : 200, isset($response['headers']) ? $response['headers'] : array(), $body);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Returns a response for given request or null if not found.
  *
  * @param Request $request Request.
  *
  * @return Response|null Response for specified request.
  */
 public function playback(Request $request)
 {
     foreach ($this->storage as $recording) {
         $storedRequest = Request::fromArray($recording['request']);
         if ($storedRequest->matches($request, $this->getRequestMatchers())) {
             return Response::fromArray($recording['response']);
         }
     }
     return null;
 }