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

Breadcrumb

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

function LazyGhostTrait::createLazyGhost

Creates a lazy-loading ghost instance.

Skipped properties should be indexed by their array-cast identifier, see https://php.net/manual/language.types.array#language.types.array.casting

Parameters

\Closure(static):void $initializer The closure should initialize the object it receives as argument:

array<string, true>|null $skippedProperties An array indexed by the properties to skip, a.k.a. the ones: that the initializer doesn't initialize, if any

static|null $instance:

File

vendor/symfony/var-exporter/LazyGhostTrait.php, line 35

Class

LazyGhostTrait

Namespace

Symfony\Component\VarExporter

Code

public static function createLazyGhost(\Closure $initializer, ?array $skippedProperties = null, ?object $instance = null) : static {
    if (self::class !== ($class = $instance ? $instance::class : static::class)) {
        $skippedProperties["\x00" . self::class . "\x00lazyObjectState"] = true;
    }
    if (!isset(Registry::$defaultProperties[$class])) {
        Registry::$classReflectors[$class] ??= new \ReflectionClass($class);
        $instance ??= Registry::$classReflectors[$class]->newInstanceWithoutConstructor();
        Registry::$defaultProperties[$class] ??= (array) $instance;
        Registry::$classResetters[$class] ??= Registry::getClassResetters($class);
        if (self::class === $class && \defined($class . '::LAZY_OBJECT_PROPERTY_SCOPES')) {
            Hydrator::$propertyScopes[$class] ??= $class::LAZY_OBJECT_PROPERTY_SCOPES;
        }
    }
    else {
        $instance ??= Registry::$classReflectors[$class]->newInstanceWithoutConstructor();
    }
    if (isset($instance->lazyObjectState)) {
        $instance->lazyObjectState->initializer = $initializer;
        $instance->lazyObjectState->skippedProperties = $skippedProperties ??= [];
        if (LazyObjectState::STATUS_UNINITIALIZED_FULL !== $instance->lazyObjectState->status) {
            $instance->lazyObjectState
                ->reset($instance);
        }
        return $instance;
    }
    $instance->lazyObjectState = new LazyObjectState($initializer, $skippedProperties ??= []);
    foreach (Registry::$classResetters[$class] as $reset) {
        $reset($instance, $skippedProperties);
    }
    return $instance;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal