ConfigCache.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\BCResourceInterfaceChecker;
  12. use Symfony\Component\Config\Resource\SelfCheckingResourceChecker;
  13. /**
  14. * ConfigCache caches arbitrary content in files on disk.
  15. *
  16. * When in debug mode, those metadata resources that implement
  17. * \Symfony\Component\Config\Resource\SelfCheckingResourceInterface will
  18. * be used to check cache freshness.
  19. *
  20. * During a transition period, also instances of
  21. * \Symfony\Component\Config\Resource\ResourceInterface will be checked
  22. * by means of the isFresh() method. This behaviour is deprecated since 2.8
  23. * and will be removed in 3.0.
  24. *
  25. * @author Fabien Potencier <fabien@symfony.com>
  26. * @author Matthias Pigulla <mp@webfactory.de>
  27. */
  28. class ConfigCache extends ResourceCheckerConfigCache
  29. {
  30. private $debug;
  31. /**
  32. * @param string $file The absolute cache path
  33. * @param bool $debug Whether debugging is enabled or not
  34. */
  35. public function __construct($file, $debug)
  36. {
  37. parent::__construct($file, array(
  38. new SelfCheckingResourceChecker(),
  39. new BCResourceInterfaceChecker(),
  40. ));
  41. $this->debug = (bool) $debug;
  42. }
  43. /**
  44. * Gets the cache file path.
  45. *
  46. * @return string The cache file path
  47. *
  48. * @deprecated since 2.7, to be removed in 3.0. Use getPath() instead.
  49. */
  50. public function __toString()
  51. {
  52. @trigger_error('ConfigCache::__toString() is deprecated since Symfony 2.7 and will be removed in 3.0. Use the getPath() method instead.', E_USER_DEPRECATED);
  53. return $this->getPath();
  54. }
  55. /**
  56. * Checks if the cache is still fresh.
  57. *
  58. * This implementation always returns true when debug is off and the
  59. * cache file exists.
  60. *
  61. * @return bool true if the cache is fresh, false otherwise
  62. */
  63. public function isFresh()
  64. {
  65. if (!$this->debug && is_file($this->getPath())) {
  66. return true;
  67. }
  68. return parent::isFresh();
  69. }
  70. }