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

Breadcrumb

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

function LazyServiceDumper::getProxyFactoryCode

Overrides DumperInterface::getProxyFactoryCode

File

vendor/symfony/dependency-injection/LazyProxy/PhpDumper/LazyServiceDumper.php, line 67

Class

LazyServiceDumper
@author Nicolas Grekas <p@tchwork.com>

Namespace

Symfony\Component\DependencyInjection\LazyProxy\PhpDumper

Code

public function getProxyFactoryCode(Definition $definition, string $id, string $factoryCode) : string {
    $instantiation = 'return';
    if ($definition->isShared()) {
        $instantiation .= \sprintf(' $container->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true));
    }
    $asGhostObject = str_contains($factoryCode, '$proxy');
    $proxyClass = $this->getProxyClass($definition, $asGhostObject);
    if (!$asGhostObject) {
        return <<<EOF
        if (true === \$lazyLoad) {
            {<span class="php-variable">$instantiation</span>} \$container->createProxy('{<span class="php-variable">$proxyClass</span>}', static fn () => \\{<span class="php-variable">$proxyClass</span>}::createLazyProxy(static fn () => {<span class="php-variable">$factoryCode</span>}));
        }


EOF;
    }
    $factoryCode = \sprintf('static fn ($proxy) => %s', $factoryCode);
    return <<<EOF
        if (true === \$lazyLoad) {
            {<span class="php-variable">$instantiation</span>} \$container->createProxy('{<span class="php-variable">$proxyClass</span>}', static fn () => \\{<span class="php-variable">$proxyClass</span>}::createLazyGhost({<span class="php-variable">$factoryCode</span>}));
        }


EOF;
}
RSS feed
Powered by Drupal