- /**
- * Saves the cookies to a file.
- *
- * @param string $filename File to save
- *
- * @throws \RuntimeException if the file cannot be found or created
- */
- public function save($filename)
- {
- $json = [];
- foreach ($this as $cookie) {
- if ($cookie->getExpires() && !$cookie->getDiscard()) {
- $json[] = $cookie->toArray();
- }
- }
-
- if (false === file_put_contents($filename, json_encode($json), LOCK_EX)) {
- // @codeCoverageIgnoreStart
- throw new \RuntimeException("Unable to save file {$filename}");
- // @codeCoverageIgnoreEnd
- }
- }
-