Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. FileCookieJar.php

function 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 57

Class

FileCookieJar
Persists non-session cookies using a JSON formatted file

Namespace

GuzzleHttp\Cookie

Code

public function save(string $filename) : void {
    $json = [];
    
    /** @var SetCookie $cookie */
    foreach ($this as $cookie) {
        if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) {
            $json[] = $cookie->toArray();
        }
    }
    $jsonStr = Utils::jsonEncode($json);
    if (false === \file_put_contents($filename, $jsonStr, \LOCK_EX)) {
        throw new \RuntimeException("Unable to save file {$filename}");
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal