vendor/symfony/dependency-injection/Compiler/Compiler.php line 30

Open in your IDE?
  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\EnvParameterException;
  13. /**
  14.  * This class is used to remove circular dependencies between individual passes.
  15.  *
  16.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  17.  */
  18. class Compiler
  19. {
  20.     private PassConfig $passConfig;
  21.     private array $log = [];
  22.     private ServiceReferenceGraph $serviceReferenceGraph;
  23.     public function __construct()
  24.     {
  25.         $this->passConfig = new PassConfig();
  26.         $this->serviceReferenceGraph = new ServiceReferenceGraph();
  27.     }
  28.     public function getPassConfig(): PassConfig
  29.     {
  30.         return $this->passConfig;
  31.     }
  32.     public function getServiceReferenceGraph(): ServiceReferenceGraph
  33.     {
  34.         return $this->serviceReferenceGraph;
  35.     }
  36.     public function addPass(CompilerPassInterface $passstring $type PassConfig::TYPE_BEFORE_OPTIMIZATIONint $priority 0)
  37.     {
  38.         $this->passConfig->addPass($pass$type$priority);
  39.     }
  40.     /**
  41.      * @final
  42.      */
  43.     public function log(CompilerPassInterface $passstring $message)
  44.     {
  45.         if (str_contains($message"\n")) {
  46.             $message str_replace("\n""\n".\get_class($pass).': 'trim($message));
  47.         }
  48.         $this->log[] = \get_class($pass).': '.$message;
  49.     }
  50.     public function getLog(): array
  51.     {
  52.         return $this->log;
  53.     }
  54.     /**
  55.      * Run the Compiler and process all Passes.
  56.      */
  57.     public function compile(ContainerBuilder $container)
  58.     {
  59.         try {
  60.             foreach ($this->passConfig->getPasses() as $pass) {
  61.                 $pass->process($container);
  62.             }
  63.         } catch (\Exception $e) {
  64.             $usedEnvs = [];
  65.             $prev $e;
  66.             do {
  67.                 $msg $prev->getMessage();
  68.                 if ($msg !== $resolvedMsg $container->resolveEnvPlaceholders($msgnull$usedEnvs)) {
  69.                     $r = new \ReflectionProperty($prev'message');
  70.                     $r->setValue($prev$resolvedMsg);
  71.                 }
  72.             } while ($prev $prev->getPrevious());
  73.             if ($usedEnvs) {
  74.                 $e = new EnvParameterException($usedEnvs$e);
  75.             }
  76.             throw $e;
  77.         } finally {
  78.             $this->getServiceReferenceGraph()->clear();
  79.         }
  80.     }
  81. }