You are here

public function FileCookieJar::save in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php \GuzzleHttp\Cookie\FileCookieJar::save()

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();
    }
  }
  if (false === file_put_contents($filename, json_encode($json))) {
    throw new \RuntimeException("Unable to save file {$filename}");
  }
}