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

Breadcrumb

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

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

Class

FileCookieJar
Persists non-session cookies using a JSON formatted file

Namespace

GuzzleHttp\Cookie

Code

public function load(string $filename) : void {
    $json = \file_get_contents($filename);
    if (false === $json) {
        throw new \RuntimeException("Unable to load file {$filename}");
    }
    if ($json === '') {
        return;
    }
    $data = Utils::jsonDecode($json, true);
    if (\is_array($data)) {
        foreach ($data as $cookie) {
            $this->setCookie(new SetCookie($cookie));
        }
    }
    elseif (\is_scalar($data) && !empty($data)) {
        throw new \RuntimeException("Invalid cookie file: {$filename}");
    }
}

API Navigation

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