ResourceCheckerConfigCacheFactory.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. private $resourceCheckers = [];
  20. /**
  21. * @param iterable|ResourceCheckerInterface[] $resourceCheckers
  22. */
  23. public function __construct(iterable $resourceCheckers = [])
  24. {
  25. $this->resourceCheckers = $resourceCheckers;
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function cache($file, $callback)
  31. {
  32. if (!\is_callable($callback)) {
  33. throw new \InvalidArgumentException(sprintf('Invalid type for callback argument. Expected callable, but got "%s".', \gettype($callback)));
  34. }
  35. $cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
  36. if (!$cache->isFresh()) {
  37. $callback($cache);
  38. }
  39. return $cache;
  40. }
  41. }