Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
FileCookieJar.php
01 <?php
02 namespace GuzzleHttp\Cookie;
03
04 use GuzzleHttp\Utils;
05
06 /**
07 * Persists non-session cookies using a JSON formatted file
08 */
09 class FileCookieJar extends CookieJar
10 {
11 /** @var string filename */
12 private $filename;
13
14 /**
15 * Create a new FileCookieJar object
16 *
17 * @param string $cookieFile File to store the cookie data
18 *
19 * @throws \RuntimeException if the file cannot be found or created
20 */
21 public function __construct($cookieFile)
22 {
23 $this->filename = $cookieFile;
24
25 if (file_exists($cookieFile)) {
26 $this->load($cookieFile);
27 }
28 }
29
30 /**
31 * Saves the file when shutting down
32 */
33 public function __destruct()
34 {
35 $this->save($this->filename);
36 }
37
38 /**
39 * Saves the cookies to a file.
40 *
41 * @param string $filename File to save
42 * @throws \RuntimeException if the file cannot be found or created
43 */
44 public function save($filename)
45 {
46 $json = [];
47 foreach ($this as $cookie) {
48 if ($cookie->getExpires() && !$cookie->getDiscard()) {
49 $json[] = $cookie->toArray();
50 }
51 }
52
53 if (false === file_put_contents($filename, json_encode($json))) {
54 // @codeCoverageIgnoreStart
55 throw new \RuntimeException("Unable to save file {$filename}");
56 // @codeCoverageIgnoreEnd
57 }
58 }
59
60 /**
61 * Load cookies from a JSON formatted file.
62 *
63 * Old cookies are kept unless overwritten by newly loaded ones.
64 *
65 * @param string $filename Cookie file to load.
66 * @throws \RuntimeException if the file cannot be loaded.
67 */
68 public function load($filename)
69 {
70 $json = file_get_contents($filename);
71 if (false === $json) {
72 // @codeCoverageIgnoreStart
73 throw new \RuntimeException("Unable to load file {$filename}");
74 // @codeCoverageIgnoreEnd
75 }
76
77 $data = Utils::jsonDecode($json, true);
78 if (is_array($data)) {
79 foreach (Utils::jsonDecode($json, true) as $cookie) {
80 $this->setCookie(new SetCookie($cookie));
81 }
82 } elseif (strlen($data)) {
83 throw new \RuntimeException("Invalid cookie file: {$filename}");
84 }
85 }
86 }
87