Пример #1
0
 public function json(array $config = array())
 {
     try {
         return puzzle_json_decode((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 puzzle_exception_ParseException($e->getMessage(), $this);
     }
 }
Пример #2
0
 /**
  * Load the contents of the client session into the data array
  */
 protected function load()
 {
     $cookieJar = isset($_SESSION[$this->sessionKey]) ? $_SESSION[$this->sessionKey] : null;
     $data = puzzle_json_decode($cookieJar, true);
     if (is_array($data)) {
         foreach ($data as $cookie) {
             $this->setCookie(new puzzle_cookie_SetCookie($cookie));
         }
     } elseif (strlen($data)) {
         throw new RuntimeException("Invalid cookie data");
     }
 }
Пример #3
0
 /**
  * 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 = puzzle_json_decode($json, true);
     if (is_array($data)) {
         foreach (puzzle_json_decode($json, true) as $cookie) {
             $this->setCookie(new puzzle_cookie_SetCookie($cookie));
         }
     } elseif (strlen($data)) {
         throw new RuntimeException("Invalid cookie file: {$filename}");
     }
 }
Пример #4
0
 public function testJsonDecodesWithErrorMessages()
 {
     if (version_compare(PHP_VERSION, '5.3') >= 0) {
         $this->setExpectedException('InvalidArgumentException', 'Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON');
     } else {
         $this->setExpectedException('InvalidArgumentException', 'Unable to parse JSON data: Unknown error');
     }
     puzzle_json_decode('!narf!');
 }