ConfigCacheFactory.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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($debug)
  27. {
  28. $this->debug = $debug;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function cache($file, $callback)
  34. {
  35. if (!\is_callable($callback)) {
  36. throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
  37. }
  38. $cache = new ConfigCache($file, $this->debug);
  39. if (!$cache->isFresh()) {
  40. \call_user_func($callback, $cache);
  41. }
  42. return $cache;
  43. }
  44. }