PassConfig.php 6.0 KB

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