Файл: vendor/symfony/var-exporter/ProxyHelper.php
Строк: 1000
<?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 SymfonyComponentVarExporter;
use SymfonyComponentVarExporterExceptionLogicException;
use SymfonyComponentVarExporterInternalHydrator;
use SymfonyComponentVarExporterInternalLazyDecoratorTrait;
use SymfonyComponentVarExporterInternalLazyObjectRegistry;
/**
* @author Nicolas Grekas <p@tchwork.com>
*/
final class ProxyHelper
{
/**
* Helps generate lazy-loading ghost objects.
*
* @deprecated since Symfony 7.3, use native lazy objects instead
*
* @throws LogicException When the class is incompatible with ghost objects
*/
public static function generateLazyGhost(ReflectionClass $class): string
{
if (PHP_VERSION_ID >= 80400) {
trigger_deprecation('symfony/var-exporter', '7.3', 'Using ProxyHelper::generateLazyGhost() is deprecated, use native lazy objects instead.');
}
if (PHP_VERSION_ID < 80300 && $class->isReadOnly()) {
throw new LogicException(sprintf('Cannot generate lazy ghost with PHP < 8.3: class "%s" is readonly.', $class->name));
}
if ($class->isFinal()) {
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is final.', $class->name));
}
if ($class->isInterface() || $class->isAbstract() || $class->isTrait()) {
throw new LogicException(sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name));
}
if (stdClass::class !== $class->name && $class->isInternal()) {
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is internal.', $class->name));
}
if ($class->hasMethod('__get') && 'mixed' !== (self::exportType($class->getMethod('__get')) ?? 'mixed')) {
throw new LogicException(sprintf('Cannot generate lazy ghost: return type of method "%s::__get()" should be "mixed".', $class->name));
}
static $traitMethods;
$traitMethods ??= (new ReflectionClass(LazyGhostTrait::class))->getMethods();
foreach ($traitMethods as $method) {
if ($class->hasMethod($method->name) && $class->getMethod($method->name)->isFinal()) {
throw new LogicException(sprintf('Cannot generate lazy ghost: method "%s::%s()" is final.', $class->name, $method->name));
}
}
$parent = $class;
while ($parent = $parent->getParentClass()) {
if (stdClass::class !== $parent->name && $parent->isInternal()) {
throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" extends "%s" which is internal.', $class->name, $parent->name));
}
}
$hooks = '';
$propertyScopes = Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name);
foreach ($propertyScopes as $key => [$scope, $name, , $access]) {
$propertyScopes[$k = " $scope