You are here

public function FileCookieJar::save in Lockr 7.3

Saves the cookies to a file.

Parameters

string $filename File to save:

Throws

\RuntimeException if the file cannot be found or created

1 call to FileCookieJar::save()
FileCookieJar::__destruct in vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php
Saves the file when shutting down

File

vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php, line 48

Class

FileCookieJar
Persists non-session cookies using a JSON formatted file

Namespace

GuzzleHttp\Cookie

Code

public function save($filename) {
  $json = [];
  foreach ($this as $cookie) {

    /** @var SetCookie $cookie */
    if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) {
      $json[] = $cookie
        ->toArray();
    }
  }
  $jsonStr = \GuzzleHttp\json_encode($json);
  if (false === file_put_contents($filename, $jsonStr)) {
    throw new \RuntimeException("Unable to save file {$filename}");
  }
}