Drupal investigation

Compiler.php 2.4KB

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