ConfigCacheFactory.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /**
  12. * Basic implementation of ConfigCacheFactoryInterface that
  13. * creates an instance of the default ConfigCache.
  14. *
  15. * This factory and/or cache <em>do not</em> support cache validation
  16. * by means of ResourceChecker instances (that is, service-based).
  17. *
  18. * @author Matthias Pigulla <mp@webfactory.de>
  19. */
  20. class ConfigCacheFactory implements ConfigCacheFactoryInterface
  21. {
  22. private $debug;
  23. /**
  24. * @param bool $debug The debug flag to pass to ConfigCache
  25. */
  26. public function __construct(bool $debug)
  27. {
  28. $this->debug = $debug;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function cache(string $file, callable $callback)
  34. {
  35. $cache = new ConfigCache($file, $this->debug);
  36. if (!$cache->isFresh()) {
  37. $callback($cache);
  38. }
  39. return $cache;
  40. }
  41. }