Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Compiler.php

class Compiler

Same name in this branch
  1. 11.1.x vendor/twig/twig/src/Compiler.php \Twig\Compiler
  2. 11.1.x vendor/composer/composer/src/Composer/Compiler.php \Composer\Compiler

This class is used to remove circular dependencies between individual passes.

@author Johannes M. Schmitt <schmittjoh@gmail.com>

Hierarchy

  • class \Symfony\Component\DependencyInjection\Compiler\Compiler

Expanded class hierarchy of Compiler

1 file declares its use of Compiler
ContainerBuilder.php in vendor/symfony/dependency-injection/ContainerBuilder.php

File

vendor/symfony/dependency-injection/Compiler/Compiler.php, line 22

Namespace

Symfony\Component\DependencyInjection\Compiler
View source
class Compiler {
    private PassConfig $passConfig;
    private array $log = [];
    private ServiceReferenceGraph $serviceReferenceGraph;
    public function __construct() {
        $this->passConfig = new PassConfig();
        $this->serviceReferenceGraph = new ServiceReferenceGraph();
    }
    public function getPassConfig() : PassConfig {
        return $this->passConfig;
    }
    public function getServiceReferenceGraph() : ServiceReferenceGraph {
        return $this->serviceReferenceGraph;
    }
    public function addPass(CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION, int $priority = 0) : void {
        $this->passConfig
            ->addPass($pass, $type, $priority);
    }
    
    /**
     * @final
     */
    public function log(CompilerPassInterface $pass, string $message) : void {
        if (str_contains($message, "\n")) {
            $message = str_replace("\n", "\n" . $pass::class . ': ', trim($message));
        }
        $this->log[] = $pass::class . ': ' . $message;
    }
    public function getLog() : array {
        return $this->log;
    }
    
    /**
     * Run the Compiler and process all Passes.
     */
    public function compile(ContainerBuilder $container) : void {
        try {
            foreach ($this->passConfig
                ->getPasses() as $pass) {
                $pass->process($container);
            }
        } catch (\Exception $e) {
            $usedEnvs = [];
            $prev = $e;
            do {
                $msg = $prev->getMessage();
                if ($msg !== ($resolvedMsg = $container->resolveEnvPlaceholders($msg, null, $usedEnvs))) {
                    $r = new \ReflectionProperty($prev, 'message');
                    $r->setValue($prev, $resolvedMsg);
                }
            } while ($prev = $prev->getPrevious());
            if ($usedEnvs) {
                $e = new EnvParameterException($usedEnvs, $e);
            }
            throw $e;
        } finally {
            $this->getServiceReferenceGraph()
                ->clear();
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
Compiler::$log private property
Compiler::$passConfig private property
Compiler::$serviceReferenceGraph private property
Compiler::addPass public function
Compiler::compile public function Run the Compiler and process all Passes.
Compiler::getLog public function
Compiler::getPassConfig public function
Compiler::getServiceReferenceGraph public function
Compiler::log public function @final
Compiler::__construct public function
RSS feed
Powered by Drupal