Drupal investigation

RepeatedPass.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Compiler;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  13. /**
  14. * A pass that might be run repeatedly.
  15. *
  16. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  17. */
  18. class RepeatedPass implements CompilerPassInterface
  19. {
  20. /**
  21. * @var bool
  22. */
  23. private $repeat = false;
  24. /**
  25. * @var RepeatablePassInterface[]
  26. */
  27. private $passes;
  28. /**
  29. * @param RepeatablePassInterface[] $passes An array of RepeatablePassInterface objects
  30. *
  31. * @throws InvalidArgumentException when the passes don't implement RepeatablePassInterface
  32. */
  33. public function __construct(array $passes)
  34. {
  35. foreach ($passes as $pass) {
  36. if (!$pass instanceof RepeatablePassInterface) {
  37. throw new InvalidArgumentException('$passes must be an array of RepeatablePassInterface.');
  38. }
  39. $pass->setRepeatedPass($this);
  40. }
  41. $this->passes = $passes;
  42. }
  43. /**
  44. * Process the repeatable passes that run more than once.
  45. *
  46. * @param ContainerBuilder $container
  47. */
  48. public function process(ContainerBuilder $container)
  49. {
  50. do {
  51. $this->repeat = false;
  52. foreach ($this->passes as $pass) {
  53. $pass->process($container);
  54. }
  55. } while ($this->repeat);
  56. }
  57. /**
  58. * Sets if the pass should repeat.
  59. */
  60. public function setRepeat()
  61. {
  62. $this->repeat = true;
  63. }
  64. /**
  65. * Returns the passes.
  66. *
  67. * @return RepeatablePassInterface[] An array of RepeatablePassInterface objects
  68. */
  69. public function getPasses()
  70. {
  71. return $this->passes;
  72. }
  73. }