for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Ivory Http Adapter package.
*
* (c) Eric GELOEN <[email protected]>
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
*/
namespace Ivory\HttpAdapter\Event\Cookie\Jar;
use Ivory\HttpAdapter\Event\Cookie\CookieFactoryInterface;
use Ivory\HttpAdapter\HttpAdapterException;
/**
* @author GeLo <[email protected]>
class FileCookieJar extends AbstractPersistentCookieJar
{
* @var string
private $file;
* @param string $file
* @param CookieFactoryInterface|null $cookieFactory
public function __construct($file, CookieFactoryInterface $cookieFactory = null)
$this->setFile($file);
parent::__construct($cookieFactory, file_exists($file));
}
* @return string
public function getFile()
return $this->file;
public function setFile($file)
$this->file = $file;
* {@inheritdoc}
public function load()
if (($data = @file_get_contents($this->file)) === false) {
$error = error_get_last();
throw HttpAdapterException::cannotLoadCookieJar($error['message']);
$this->unserialize($data);
public function save()
if (@file_put_contents($this->file, $this->serialize()) === false) {
throw HttpAdapterException::cannotSaveCookieJar($error['message']);