Файл: vendor/symfony/var-exporter/Internal/LazyObjectState.php
Строк: 117
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SymfonyComponentVarExporterInternal;
use SymfonyComponentVarExporterHydrator as PublicHydrator;
/**
* Keeps the state of lazy objects.
*
* As a micro-optimization, this class uses no type declarations.
*
* @internal
*/
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;
public object $cloneInstance;
/**
* @param array<string, true> $skippedProperties
*/
public function __construct(
public ?Closure $initializer = null,
public array $skippedProperties = [],
) {
}
public function initialize($instance, $propertyName, $writeScope)
{
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, , $access]) {
$propertyScopes[$k = " $scope