ConfigCache.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config;
  11. use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
  12. /**
  13. * ConfigCache caches arbitrary content in files on disk.
  14. *
  15. * When in debug mode, those metadata resources that implement
  16. * \Symfony\Component\Config\Resource\SelfCheckingResourceInterface will
  17. * be used to check cache freshness.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. * @author Matthias Pigulla <mp@webfactory.de>
  21. */
  22. class ConfigCache extends ResourceCheckerConfigCache
  23. {
  24. private $debug;
  25. /**
  26. * @param string $file The absolute cache path
  27. * @param bool $debug Whether debugging is enabled or not
  28. */
  29. public function __construct(string $file, bool $debug)
  30. {
  31. $this->debug = $debug;
  32. $checkers = [];
  33. if (true === $this->debug) {
  34. $checkers = [new SelfCheckingResourceChecker()];
  35. }
  36. parent::__construct($file, $checkers);
  37. }
  38. /**
  39. * Checks if the cache is still fresh.
  40. *
  41. * This implementation always returns true when debug is off and the
  42. * cache file exists.
  43. *
  44. * @return bool true if the cache is fresh, false otherwise
  45. */
  46. public function isFresh()
  47. {
  48. if (!$this->debug && is_file($this->getPath())) {
  49. return true;
  50. }
  51. return parent::isFresh();
  52. }
  53. }