You are here

public function FileCookieJar::load in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php \GuzzleHttp\Cookie\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 71

Class

FileCookieJar
Persists non-session cookies using a JSON formatted file

Namespace

GuzzleHttp\Cookie

Code

public function load($filename) {
  $json = file_get_contents($filename);
  if (false === $json) {
    throw new \RuntimeException("Unable to load file {$filename}");
  }
  $data = json_decode($json, true);
  if (is_array($data)) {
    foreach (json_decode($json, true) as $cookie) {
      $this
        ->setCookie(new SetCookie($cookie));
    }
  }
  elseif (strlen($data)) {
    throw new \RuntimeException("Invalid cookie file: {$filename}");
  }
}