2011-02-10 15:15:51 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-02-10 15:15:51 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Config;
|
|
|
|
|
2015-09-09 12:50:25 +01:00
|
|
|
use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
|
2012-11-01 15:08:59 +00:00
|
|
|
|
2011-02-10 15:15:51 +00:00
|
|
|
/**
|
2015-09-09 12:50:25 +01:00
|
|
|
* ConfigCache caches arbitrary content in files on disk.
|
2011-02-10 15:15:51 +00:00
|
|
|
*
|
2015-09-09 12:50:25 +01:00
|
|
|
* When in debug mode, those metadata resources that implement
|
|
|
|
* \Symfony\Component\Config\Resource\SelfCheckingResourceInterface will
|
|
|
|
* be used to check cache freshness.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* @author Fabien Potencier <fabien@symfony.com>
|
2015-09-09 12:50:25 +01:00
|
|
|
* @author Matthias Pigulla <mp@webfactory.de>
|
2011-02-10 15:15:51 +00:00
|
|
|
*/
|
2015-09-09 12:50:25 +01:00
|
|
|
class ConfigCache extends ResourceCheckerConfigCache
|
2011-02-10 15:15:51 +00:00
|
|
|
{
|
2011-03-23 18:34:00 +00:00
|
|
|
private $debug;
|
2011-02-10 15:15:51 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-30 13:33:44 +00:00
|
|
|
* @param string $file The absolute cache path
|
|
|
|
* @param bool $debug Whether debugging is enabled or not
|
2011-02-10 15:15:51 +00:00
|
|
|
*/
|
2017-10-28 19:15:32 +01:00
|
|
|
public function __construct(string $file, bool $debug)
|
2011-02-10 15:15:51 +00:00
|
|
|
{
|
2017-10-28 19:15:32 +01:00
|
|
|
$this->debug = $debug;
|
2016-10-01 06:24:10 +01:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$checkers = [];
|
2016-10-01 06:24:10 +01:00
|
|
|
if (true === $this->debug) {
|
2019-01-16 09:39:14 +00:00
|
|
|
$checkers = [new SelfCheckingResourceChecker()];
|
2016-10-01 06:24:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($file, $checkers);
|
2011-02-10 15:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the cache is still fresh.
|
|
|
|
*
|
2015-09-09 12:50:25 +01:00
|
|
|
* This implementation always returns true when debug is off and the
|
2011-05-19 07:05:27 +01:00
|
|
|
* cache file exists.
|
2011-02-10 15:15:51 +00:00
|
|
|
*
|
2014-11-30 13:33:44 +00:00
|
|
|
* @return bool true if the cache is fresh, false otherwise
|
2011-02-10 15:15:51 +00:00
|
|
|
*/
|
|
|
|
public function isFresh()
|
|
|
|
{
|
2015-09-09 12:50:25 +01:00
|
|
|
if (!$this->debug && is_file($this->getPath())) {
|
2011-02-10 15:15:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 12:50:25 +01:00
|
|
|
return parent::isFresh();
|
2013-04-21 08:24:34 +01:00
|
|
|
}
|
2011-02-10 15:15:51 +00:00
|
|
|
}
|