Compiler.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  13. * This class is used to remove circular dependencies between individual passes.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class Compiler
  18. {
  19. private $passConfig;
  20. private $log = array();
  21. private $loggingFormatter;
  22. private $serviceReferenceGraph;
  23. /**
  24. * Constructor.
  25. */
  26. public function __construct()
  27. {
  28. $this->passConfig = new PassConfig();
  29. $this->serviceReferenceGraph = new ServiceReferenceGraph();
  30. $this->loggingFormatter = new LoggingFormatter();
  31. }
  32. /**
  33. * Returns the PassConfig.
  34. *
  35. * @return PassConfig The PassConfig instance
  36. */
  37. public function getPassConfig()
  38. {
  39. return $this->passConfig;
  40. }
  41. /**
  42. * Returns the ServiceReferenceGraph.
  43. *
  44. * @return ServiceReferenceGraph The ServiceReferenceGraph instance
  45. */
  46. public function getServiceReferenceGraph()
  47. {
  48. return $this->serviceReferenceGraph;
  49. }
  50. /**
  51. * Returns the logging formatter which can be used by compilation passes.
  52. *
  53. * @return LoggingFormatter
  54. */
  55. public function getLoggingFormatter()
  56. {
  57. return $this->loggingFormatter;
  58. }
  59. /**
  60. * Adds a pass to the PassConfig.
  61. *
  62. * @param CompilerPassInterface $pass A compiler pass
  63. * @param string $type The type of the pass
  64. */
  65. public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
  66. {
  67. $this->passConfig->addPass($pass, $type);
  68. }
  69. /**
  70. * Adds a log message.
  71. *
  72. * @param string $string The log message
  73. */
  74. public function addLogMessage($string)
  75. {
  76. $this->log[] = $string;
  77. }
  78. /**
  79. * Returns the log.
  80. *
  81. * @return array Log array
  82. */
  83. public function getLog()
  84. {
  85. return $this->log;
  86. }
  87. /**
  88. * Run the Compiler and process all Passes.
  89. *
  90. * @param ContainerBuilder $container
  91. */
  92. public function compile(ContainerBuilder $container)
  93. {
  94. foreach ($this->passConfig->getPasses() as $pass) {
  95. $pass->process($container);
  96. }
  97. }
  98. }