ResourceCheckerConfigCacheFactory.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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(string $file, callable $callable)
  31. {
  32. $cache = new ResourceCheckerConfigCache($file, $this->resourceCheckers);
  33. if (!$cache->isFresh()) {
  34. $callable($cache);
  35. }
  36. return $cache;
  37. }
  38. }