ResourceCheckerConfigCacheFactory.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. * A ConfigCacheFactory implementation that validates the
  13. * cache with an arbitrary set of ResourceCheckers.
  14. *
  15. * @author Matthias Pigulla <mp@webfactory.de>
  16. */
  17. class ResourceCheckerConfigCacheFactory implements ConfigCacheFactoryInterface
  18. {
  19. /**
  20. * @var ResourceCheckerInterface[]
  21. */
  22. private $resourceCheckers = array();
  23. /**
  24. * @param ResourceCheckerInterface[] $resourceCheckers
  25. */
  26. public function __construct(array $resourceCheckers = array())
  27. {
  28. $this->resourceCheckers = $resourceCheckers;
  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 ResourceCheckerConfigCache($file, $this->resourceCheckers);
  39. if (!$cache->isFresh()) {
  40. \call_user_func($callback, $cache);
  41. }
  42. return $cache;
  43. }
  44. }