function FileCookieJar::load
Load cookies from a JSON formatted file.
Old cookies are kept unless overwritten by newly loaded ones.
Parameters
string $filename Cookie file to load.:
Throws
\RuntimeException if the file cannot be loaded.
1 call to FileCookieJar::load()
- FileCookieJar::__construct in vendor/
guzzlehttp/ guzzle/ src/ Cookie/ FileCookieJar.php - Create a new FileCookieJar object
File
-
vendor/
guzzlehttp/ guzzle/ src/ Cookie/ FileCookieJar.php, line 82
Class
- FileCookieJar
- Persists non-session cookies using a JSON formatted file
Namespace
GuzzleHttp\CookieCode
public function load(string $filename) : void {
$json = \file_get_contents($filename);
if (false === $json) {
throw new \RuntimeException("Unable to load file {$filename}");
}
if ($json === '') {
return;
}
$data = Utils::jsonDecode($json, true);
if (\is_array($data)) {
foreach ($data as $cookie) {
$this->setCookie(new SetCookie($cookie));
}
}
elseif (\is_scalar($data) && !empty($data)) {
throw new \RuntimeException("Invalid cookie file: {$filename}");
}
}