ConfigCacheFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /**
  23. * @var bool Debug flag passed to the ConfigCache
  24. */
  25. private $debug;
  26. /**
  27. * @param bool $debug The debug flag to pass to ConfigCache
  28. */
  29. public function __construct($debug)
  30. {
  31. $this->debug = $debug;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function cache($file, $callback)
  37. {
  38. if (!is_callable($callback)) {
  39. throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', gettype($callback)));
  40. }
  41. $cache = new ConfigCache($file, $this->debug);
  42. if (!$cache->isFresh()) {
  43. call_user_func($callback, $cache);
  44. }
  45. return $cache;
  46. }
  47. }