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

Breadcrumb

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

function LazyServiceDumper::isProxyCandidate

Overrides DumperInterface::isProxyCandidate

1 call to LazyServiceDumper::isProxyCandidate()
LazyServiceDumper::getProxyCode in vendor/symfony/dependency-injection/LazyProxy/PhpDumper/LazyServiceDumper.php
Generates the code for the lazy proxy.

File

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

Class

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

Namespace

Symfony\Component\DependencyInjection\LazyProxy\PhpDumper

Code

public function isProxyCandidate(Definition $definition, ?bool &$asGhostObject = null, ?string $id = null) : bool {
    $asGhostObject = false;
    if ($definition->hasTag('proxy')) {
        if (!$definition->isLazy()) {
            throw new InvalidArgumentException(\sprintf('Invalid definition for service "%s": setting the "proxy" tag on a service requires it to be "lazy".', $id ?? $definition->getClass()));
        }
        return true;
    }
    if (!$definition->isLazy()) {
        return false;
    }
    if (!($class = $definition->getClass()) || !(class_exists($class) || interface_exists($class, false))) {
        return false;
    }
    if ($definition->getFactory()) {
        return true;
    }
    foreach ($definition->getMethodCalls() as $call) {
        if ($call[2] ?? false) {
            return true;
        }
    }
    try {
        $asGhostObject = (bool) ProxyHelper::generateLazyGhost(new \ReflectionClass($class));
    } catch (LogicException) {
    }
    return true;
}
RSS feed
Powered by Drupal