Drupal investigation

PassConfig.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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\Exception\InvalidArgumentException;
  12. /**
  13. * Compiler Pass Configuration.
  14. *
  15. * This class has a default configuration embedded.
  16. *
  17. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  18. */
  19. class PassConfig
  20. {
  21. const TYPE_AFTER_REMOVING = 'afterRemoving';
  22. const TYPE_BEFORE_OPTIMIZATION = 'beforeOptimization';
  23. const TYPE_BEFORE_REMOVING = 'beforeRemoving';
  24. const TYPE_OPTIMIZE = 'optimization';
  25. const TYPE_REMOVE = 'removing';
  26. private $mergePass;
  27. private $afterRemovingPasses = array();
  28. private $beforeOptimizationPasses = array();
  29. private $beforeRemovingPasses = array();
  30. private $optimizationPasses;
  31. private $removingPasses;
  32. public function __construct()
  33. {
  34. $this->mergePass = new MergeExtensionConfigurationPass();
  35. $this->optimizationPasses = array(
  36. new ExtensionCompilerPass(),
  37. new ResolveDefinitionTemplatesPass(),
  38. new DecoratorServicePass(),
  39. new ResolveParameterPlaceHoldersPass(),
  40. new CheckDefinitionValidityPass(),
  41. new ResolveReferencesToAliasesPass(),
  42. new ResolveInvalidReferencesPass(),
  43. new AutowirePass(),
  44. new AnalyzeServiceReferencesPass(true),
  45. new CheckCircularReferencesPass(),
  46. new CheckReferenceValidityPass(),
  47. );
  48. $this->removingPasses = array(
  49. new RemovePrivateAliasesPass(),
  50. new ReplaceAliasByActualDefinitionPass(),
  51. new RemoveAbstractDefinitionsPass(),
  52. new RepeatedPass(array(
  53. new AnalyzeServiceReferencesPass(),
  54. new InlineServiceDefinitionsPass(),
  55. new AnalyzeServiceReferencesPass(),
  56. new RemoveUnusedDefinitionsPass(),
  57. )),
  58. new CheckExceptionOnInvalidReferenceBehaviorPass(),
  59. );
  60. }
  61. /**
  62. * Returns all passes in order to be processed.
  63. *
  64. * @return array An array of all passes to process
  65. */
  66. public function getPasses()
  67. {
  68. return array_merge(
  69. array($this->mergePass),
  70. $this->beforeOptimizationPasses,
  71. $this->optimizationPasses,
  72. $this->beforeRemovingPasses,
  73. $this->removingPasses,
  74. $this->afterRemovingPasses
  75. );
  76. }
  77. /**
  78. * Adds a pass.
  79. *
  80. * @param CompilerPassInterface $pass A Compiler pass
  81. * @param string $type The pass type
  82. *
  83. * @throws InvalidArgumentException when a pass type doesn't exist
  84. */
  85. public function addPass(CompilerPassInterface $pass, $type = self::TYPE_BEFORE_OPTIMIZATION)
  86. {
  87. $property = $type.'Passes';
  88. if (!isset($this->$property)) {
  89. throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
  90. }
  91. $this->{$property}[] = $pass;
  92. }
  93. /**
  94. * Gets all passes for the AfterRemoving pass.
  95. *
  96. * @return array An array of passes
  97. */
  98. public function getAfterRemovingPasses()
  99. {
  100. return $this->afterRemovingPasses;
  101. }
  102. /**
  103. * Gets all passes for the BeforeOptimization pass.
  104. *
  105. * @return array An array of passes
  106. */
  107. public function getBeforeOptimizationPasses()
  108. {
  109. return $this->beforeOptimizationPasses;
  110. }
  111. /**
  112. * Gets all passes for the BeforeRemoving pass.
  113. *
  114. * @return array An array of passes
  115. */
  116. public function getBeforeRemovingPasses()
  117. {
  118. return $this->beforeRemovingPasses;
  119. }
  120. /**
  121. * Gets all passes for the Optimization pass.
  122. *
  123. * @return array An array of passes
  124. */
  125. public function getOptimizationPasses()
  126. {
  127. return $this->optimizationPasses;
  128. }
  129. /**
  130. * Gets all passes for the Removing pass.
  131. *
  132. * @return array An array of passes
  133. */
  134. public function getRemovingPasses()
  135. {
  136. return $this->removingPasses;
  137. }
  138. /**
  139. * Gets the Merge pass.
  140. *
  141. * @return CompilerPassInterface The merge pass
  142. */
  143. public function getMergePass()
  144. {
  145. return $this->mergePass;
  146. }
  147. /**
  148. * Sets the Merge Pass.
  149. *
  150. * @param CompilerPassInterface $pass The merge pass
  151. */
  152. public function setMergePass(CompilerPassInterface $pass)
  153. {
  154. $this->mergePass = $pass;
  155. }
  156. /**
  157. * Sets the AfterRemoving passes.
  158. *
  159. * @param array $passes An array of passes
  160. */
  161. public function setAfterRemovingPasses(array $passes)
  162. {
  163. $this->afterRemovingPasses = $passes;
  164. }
  165. /**
  166. * Sets the BeforeOptimization passes.
  167. *
  168. * @param array $passes An array of passes
  169. */
  170. public function setBeforeOptimizationPasses(array $passes)
  171. {
  172. $this->beforeOptimizationPasses = $passes;
  173. }
  174. /**
  175. * Sets the BeforeRemoving passes.
  176. *
  177. * @param array $passes An array of passes
  178. */
  179. public function setBeforeRemovingPasses(array $passes)
  180. {
  181. $this->beforeRemovingPasses = $passes;
  182. }
  183. /**
  184. * Sets the Optimization passes.
  185. *
  186. * @param array $passes An array of passes
  187. */
  188. public function setOptimizationPasses(array $passes)
  189. {
  190. $this->optimizationPasses = $passes;
  191. }
  192. /**
  193. * Sets the Removing passes.
  194. *
  195. * @param array $passes An array of passes
  196. */
  197. public function setRemovingPasses(array $passes)
  198. {
  199. $this->removingPasses = $passes;
  200. }
  201. }