Example #1
0
 /**
  * The inverse operation of calling toResponse.
  *
  * This function will attempt to parse a Response object into an
  * ApiResponse object, which can be useful for introspection and testing.
  *
  * @param Response $response
  *
  * @throws CoreException
  * @return static
  */
 public static function fromResponse(Response $response)
 {
     $body = Json::decode($response->getContent());
     $result = Spec::define(['messages' => Boa::arrOf(Boa::string()), 'status' => Boa::in(static::getValidStatuses()), 'code' => Boa::integer()])->check($body);
     if ($result->failed()) {
         throw new CoreException('Unable to parse an ApiResponse out of the content of a' . ' Response object. Make sure that the Response object was' . ' actually generated by an ApiResponse or a compatible' . ' implementation.');
     }
     return new static(Arr::except($body, static::getReservedKeys()), $body['status'], $body['messages']);
 }
Example #2
0
 /**
  * Placeholder.
  *
  * @param mixed $value
  * @param int $options
  * @param int $depth
  *
  * @deprecated See Json::decode
  * @return mixed
  */
 public static function jsonDecode($value, $options = 0, $depth = 512)
 {
     return Json::decode($value, $options, $depth);
 }