示例#1
0
 public function json(array $config = [])
 {
     try {
         return Utils::jsonDecode((string) $this->getBody(), isset($config['object']) ? !$config['object'] : true, 512, isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0);
     } catch (\InvalidArgumentException $e) {
         throw new ParseException($e->getMessage(), $this);
     }
 }
 /**
  * Load the contents of the client session into the data array
  */
 protected function load()
 {
     $cookieJar = isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : null;
     $data = Utils::jsonDecode($cookieJar, true);
     if (is_array($data)) {
         foreach ($data as $cookie) {
             $this->setCookie(new SetCookie($cookie));
         }
     } elseif (strlen($data)) {
         throw new \RuntimeException("Invalid cookie data");
     }
 }
 /**
  * Load cookies from a JSON formatted file.
  *
  * Old cookies are kept unless overwritten by newly loaded ones.
  *
  * @param string $filename Cookie file to load.
  * @throws \RuntimeException if the file cannot be loaded.
  */
 public function load($filename)
 {
     $json = file_get_contents($filename);
     if (false === $json) {
         // @codeCoverageIgnoreStart
         throw new \RuntimeException("Unable to load file {$filename}");
         // @codeCoverageIgnoreEnd
     }
     $data = Utils::jsonDecode($json, true);
     if (is_array($data)) {
         foreach (Utils::jsonDecode($json, true) as $cookie) {
             $this->setCookie(new SetCookie($cookie));
         }
     } elseif (strlen($data)) {
         throw new \RuntimeException("Invalid cookie file: {$filename}");
     }
 }
示例#4
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON
  */
 public function testJsonDecodesWithErrorMessages()
 {
     Utils::jsonDecode('!narf!');
 }