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