ContainerParametersResourceChecker.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\DependencyInjection\Config;
  11. use Symfony\Component\Config\Resource\ResourceInterface;
  12. use Symfony\Component\Config\ResourceCheckerInterface;
  13. use Symfony\Component\DependencyInjection\ContainerInterface;
  14. /**
  15. * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
  16. */
  17. class ContainerParametersResourceChecker implements ResourceCheckerInterface
  18. {
  19. /** @var ContainerInterface */
  20. private $container;
  21. public function __construct(ContainerInterface $container)
  22. {
  23. $this->container = $container;
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function supports(ResourceInterface $metadata)
  29. {
  30. return $metadata instanceof ContainerParametersResource;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function isFresh(ResourceInterface $resource, int $timestamp)
  36. {
  37. foreach ($resource->getParameters() as $key => $value) {
  38. if (!$this->container->hasParameter($key) || $this->container->getParameter($key) !== $value) {
  39. return false;
  40. }
  41. }
  42. return true;
  43. }
  44. }