This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Config/ConfigCache.php

63 lines
1.5 KiB
PHP
Raw Normal View History

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