13 private $storeSessionCookies;
24 public function __construct($cookieFile, $storeSessionCookies =
false)
26 parent::__construct();
27 $this->filename = $cookieFile;
28 $this->storeSessionCookies = $storeSessionCookies;
30 if (file_exists($cookieFile)) {
31 $this->
load($cookieFile);
40 $this->
save($this->filename);
49 public function save($filename)
52 foreach ($this as $cookie) {
55 $json[] = $cookie->toArray();
59 $jsonStr = \GuzzleHttp\json_encode($json);
60 if (
false === file_put_contents($filename, $jsonStr, LOCK_EX)) {
61 throw new \RuntimeException(
"Unable to save file {$filename}");
73 public function load($filename)
75 $json = file_get_contents($filename);
76 if (
false === $json) {
77 throw new \RuntimeException(
"Unable to load file {$filename}");
78 } elseif ($json ===
'') {
82 $data = \GuzzleHttp\json_decode($json,
true);
83 if (is_array($data)) {
87 } elseif (strlen($data)) {
88 throw new \RuntimeException(
"Invalid cookie file: {$filename}");