Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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 = 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");
     }
 }
Ejemplo n.º 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 = 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}");
     }
 }
Ejemplo n.º 4
0
 public function testAddsDefaultUserAgentHeaderWithoutDefaultOptions()
 {
     $client = new Client();
     $this->assertEquals(['User-Agent' => Utils::getDefaultUserAgent()], $client->getDefaultOption('headers'));
 }
Ejemplo n.º 5
0
 /**
  * @deprecated Use GuzzleHttp5Legacy\Utils::getDefaultUserAgent
  */
 public static function getDefaultUserAgent()
 {
     return Utils::getDefaultUserAgent();
 }
Ejemplo n.º 6
0
 public function testProvidesDefaultUserAgent()
 {
     $ua = Utils::getDefaultUserAgent();
     $this->assertEquals(1, preg_match('#^Guzzle/.+ curl/.+ PHP/.+$#', $ua));
 }