class LazyObjectState
Keeps the state of lazy objects.
As a micro-optimization, this class uses no type declarations.
@internal
Hierarchy
- class \Symfony\Component\VarExporter\Internal\LazyObjectState
Expanded class hierarchy of LazyObjectState
3 files declare their use of LazyObjectState
- LazyGhostTrait.php in vendor/
symfony/ var-exporter/ LazyGhostTrait.php - LazyProxyTrait.php in vendor/
symfony/ var-exporter/ LazyProxyTrait.php - SymfonyCaster.php in vendor/
symfony/ var-dumper/ Caster/ SymfonyCaster.php
File
-
vendor/
symfony/ var-exporter/ Internal/ LazyObjectState.php, line 23
Namespace
Symfony\Component\VarExporter\InternalView source
class LazyObjectState {
public const STATUS_UNINITIALIZED_FULL = 1;
public const STATUS_UNINITIALIZED_PARTIAL = 2;
public const STATUS_INITIALIZED_FULL = 3;
public const STATUS_INITIALIZED_PARTIAL = 4;
/**
* @var self::STATUS_*
*/
public int $status = self::STATUS_UNINITIALIZED_FULL;
public object $realInstance;
/**
* @param array<string, true> $skippedProperties
*/
public function __construct(\Closure $initializer, array $skippedProperties = []) {
}
public function initialize($instance, $propertyName, $propertyScope) {
if (self::STATUS_UNINITIALIZED_FULL !== $this->status) {
return $this->status;
}
$this->status = self::STATUS_INITIALIZED_PARTIAL;
try {
if ($defaultProperties = array_diff_key(LazyObjectRegistry::$defaultProperties[$instance::class], $this->skippedProperties)) {
PublicHydrator::hydrate($instance, $defaultProperties);
}
($this->initializer)($instance);
} catch (\Throwable $e) {
$this->status = self::STATUS_UNINITIALIZED_FULL;
$this->reset($instance);
throw $e;
}
return $this->status = self::STATUS_INITIALIZED_FULL;
}
public function reset($instance) : void {
$class = $instance::class;
$propertyScopes = Hydrator::$propertyScopes[$class] ??= Hydrator::getPropertyScopes($class);
$skippedProperties = $this->skippedProperties;
$properties = (array) $instance;
foreach ($propertyScopes as $key => [
$scope,
$name,
$readonlyScope,
]) {
$propertyScopes[$k = "\x00{$scope}\x00{$name}"] ?? $propertyScopes[$k = "\x00*\x00{$name}"] ?? ($k = $name);
if ($k === $key && (null !== $readonlyScope || !\array_key_exists($k, $properties))) {
$skippedProperties[$k] = true;
}
}
foreach (LazyObjectRegistry::$classResetters[$class] as $reset) {
$reset($instance, $skippedProperties);
}
foreach ((array) $instance as $name => $value) {
if ("\x00" !== ($name[0] ?? '') && !\array_key_exists($name, $skippedProperties)) {
unset($instance->{$name});
}
}
$this->status = self::STATUS_UNINITIALIZED_FULL;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
LazyObjectState::$realInstance | public | property | |
LazyObjectState::$status | public | property | |
LazyObjectState::initialize | public | function | |
LazyObjectState::reset | public | function | |
LazyObjectState::STATUS_INITIALIZED_FULL | public | constant | |
LazyObjectState::STATUS_INITIALIZED_PARTIAL | public | constant | |
LazyObjectState::STATUS_UNINITIALIZED_FULL | public | constant | |
LazyObjectState::STATUS_UNINITIALIZED_PARTIAL | public | constant | |
LazyObjectState::__construct | public | function |