diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index 5e958d1865300..fb0d3f6973b80 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -50,26 +50,38 @@ protected function resetService($name): void if (!$manager instanceof LazyLoadingInterface) { throw new \LogicException('Resetting a non-lazy manager service is not supported. '.(interface_exists(LazyLoadingInterface::class) && class_exists(RuntimeInstantiator::class) ? sprintf('Declare the "%s" service as lazy.', $name) : 'Try running "composer require symfony/proxy-manager-bridge".')); } + + $load = \Closure::bind(function () use ($name) { + if (isset($this->aliases[$name])) { + $name = $this->aliases[$name]; + } + if (isset($this->fileMap[$name])) { + return fn ($lazyLoad) => $this->load($this->fileMap[$name], $lazyLoad); + } + + return $this->{$this->methodMap[$name]}(...); + }, $this->container, Container::class)(); + if ($manager instanceof GhostObjectInterface) { - throw new \LogicException('Resetting a lazy-ghost-object manager service is not supported.'); - } - $manager->setProxyInitializer(\Closure::bind( - function (&$wrappedInstance, LazyLoadingInterface $manager) use ($name) { - if (isset($this->aliases[$name])) { - $name = $this->aliases[$name]; - } - if (isset($this->fileMap[$name])) { - $wrappedInstance = $this->load($this->fileMap[$name], false); - } else { - $wrappedInstance = $this->{$this->methodMap[$name]}(false); + $initializer = function (GhostObjectInterface $manager, string $method, array $parameters, &$initializer, array $properties) use ($load) { + $instance = $load($manager); + $initializer = null; + + if ($instance !== $manager) { + throw new \LogicException(sprintf('A lazy initializer should return the ghost object proxy it was given as argument, but an instance of "%s" was returned.', get_debug_type($instance))); } + return true; + }; + } else { + $initializer = function (&$wrappedInstance, LazyLoadingInterface $manager) use ($load) { + $wrappedInstance = $load(false); $manager->setProxyInitializer(null); return true; - }, - $this->container, - Container::class - )); + }; + } + + $manager->setProxyInitializer($initializer); } } diff --git a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php index dd7dabcc87db1..e689f61ee8aac 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php @@ -12,8 +12,7 @@ namespace Symfony\Bridge\Doctrine\Tests; use PHPUnit\Framework\TestCase; -use ProxyManager\Proxy\LazyLoadingInterface; -use ProxyManager\Proxy\ValueHolderInterface; +use ProxyManager\Proxy\GhostObjectInterface; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest; @@ -38,13 +37,16 @@ public function testResetService() $registry->setTestContainer($container); $foo = $container->get('foo'); - $foo->bar = 123; - $this->assertTrue(isset($foo->bar)); + $foo->bar = 234; + $this->assertSame(234, $foo->bar); $registry->resetManager(); + self::assertFalse($foo->isProxyInitialized()); + $foo->initializeProxy(); + $this->assertSame($foo, $container->get('foo')); - $this->assertObjectNotHasAttribute('bar', $foo); + $this->assertSame(123, $foo->bar); } /** @@ -77,8 +79,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() $service = $container->get('foo'); self::assertInstanceOf(\stdClass::class, $service); - self::assertInstanceOf(LazyLoadingInterface::class, $service); - self::assertInstanceOf(ValueHolderInterface::class, $service); + self::assertInstanceOf(GhostObjectInterface::class, $service); self::assertFalse($service->isProxyInitialized()); $service->initializeProxy(); @@ -87,12 +88,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther() self::assertTrue($service->isProxyInitialized()); $registry->resetManager(); - $service->initializeProxy(); - - $wrappedValue = $service->getWrappedValueHolderValue(); - self::assertInstanceOf(\stdClass::class, $wrappedValue); - self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue); - self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue); + self::assertFalse($service->isProxyInitialized()); } private function dumpLazyServiceProjectAsFilesServiceContainer() @@ -104,6 +100,7 @@ private function dumpLazyServiceProjectAsFilesServiceContainer() $container = new ContainerBuilder(); $container->register('foo', \stdClass::class) + ->setProperty('bar', 123) ->setPublic(true) ->setLazy(true); $container->compile(); diff --git a/src/Symfony/Bridge/Doctrine/composer.json b/src/Symfony/Bridge/Doctrine/composer.json index 8de4371499e8d..2ff1d43f4deed 100644 --- a/src/Symfony/Bridge/Doctrine/composer.json +++ b/src/Symfony/Bridge/Doctrine/composer.json @@ -28,14 +28,14 @@ "symfony/stopwatch": "^5.4|^6.0", "symfony/cache": "^5.4|^6.0", "symfony/config": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4|^6.0", + "symfony/dependency-injection": "^6.2", "symfony/form": "^5.4.9|^6.0.9", "symfony/http-kernel": "^5.4|^6.0", "symfony/messenger": "^5.4|^6.0", "symfony/doctrine-messenger": "^5.4|^6.0", "symfony/property-access": "^5.4|^6.0", "symfony/property-info": "^5.4|^6.0", - "symfony/proxy-manager-bridge": "^5.4|^6.0", + "symfony/proxy-manager-bridge": "^6.2", "symfony/security-core": "^6.0", "symfony/expression-language": "^5.4|^6.0", "symfony/uid": "^5.4|^6.0", @@ -55,7 +55,7 @@ "doctrine/orm": "<2.7.4", "phpunit/phpunit": "<5.4.3", "symfony/cache": "<5.4", - "symfony/dependency-injection": "<5.4", + "symfony/dependency-injection": "<6.2", "symfony/form": "<5.4", "symfony/http-kernel": "<5.4", "symfony/messenger": "<5.4", diff --git a/src/Symfony/Bridge/ProxyManager/Internal/ProxyGenerator.php b/src/Symfony/Bridge/ProxyManager/Internal/ProxyGenerator.php index b5cc2160c4019..3f97bca44d62d 100644 --- a/src/Symfony/Bridge/ProxyManager/Internal/ProxyGenerator.php +++ b/src/Symfony/Bridge/ProxyManager/Internal/ProxyGenerator.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\ProxyManager\Internal; use Laminas\Code\Generator\ClassGenerator; +use ProxyManager\ProxyGenerator\LazyLoadingGhostGenerator; use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator; use ProxyManager\ProxyGenerator\ProxyGeneratorInterface; use Symfony\Component\DependencyInjection\Definition; @@ -21,12 +22,22 @@ */ class ProxyGenerator implements ProxyGeneratorInterface { + private readonly ProxyGeneratorInterface $generator; + + public function asGhostObject(bool $asGhostObject): static + { + $clone = clone $this; + $clone->generator = $asGhostObject ? new LazyLoadingGhostGenerator() : new LazyLoadingValueHolderGenerator(); + + return $clone; + } + /** * {@inheritdoc} */ public function generate(\ReflectionClass $originalClass, ClassGenerator $classGenerator, array $proxyOptions = []): void { - (new LazyLoadingValueHolderGenerator())->generate($originalClass, $classGenerator, $proxyOptions); + $this->generator->generate($originalClass, $classGenerator, $proxyOptions); foreach ($classGenerator->getMethods() as $method) { if (str_starts_with($originalClass->getFilename(), __FILE__)) { @@ -41,18 +52,30 @@ public function generate(\ReflectionClass $originalClass, ClassGenerator $classG } } - public function getProxifiedClass(Definition $definition): ?string + public function getProxifiedClass(Definition $definition, bool &$asGhostObject = null): ?string { if (!$definition->hasTag('proxy')) { if (!($class = $definition->getClass()) || !(class_exists($class) || interface_exists($class, false))) { return null; } - return (new \ReflectionClass($class))->name; + $class = new \ReflectionClass($class); + $name = $class->name; + + if ($asGhostObject = !$class->isAbstract() && !$class->isInterface() && ('stdClass' === $class->name || !$class->isInternal())) { + while ($class = $class->getParentClass()) { + if (!$asGhostObject = 'stdClass' === $class->name || !$class->isInternal()) { + break; + } + } + } + + return $name; } if (!$definition->isLazy()) { throw new \InvalidArgumentException(sprintf('Invalid definition for service of class "%s": setting the "proxy" tag on a service requires it to be "lazy".', $definition->getClass())); } + $asGhostObject = false; $tags = $definition->getTag('proxy'); if (!isset($tags[0]['interface'])) { throw new \InvalidArgumentException(sprintf('Invalid definition for service of class "%s": the "interface" attribute is missing on the "proxy" tag.', $definition->getClass())); diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php index 1db05b44dee2b..2684e14d60a65 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/Instantiator/RuntimeInstantiator.php @@ -12,8 +12,10 @@ namespace Symfony\Bridge\ProxyManager\LazyProxy\Instantiator; use ProxyManager\Configuration; +use ProxyManager\Factory\LazyLoadingGhostFactory; use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\GeneratorStrategy\EvaluatingGeneratorStrategy; +use ProxyManager\Proxy\GhostObjectInterface; use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Bridge\ProxyManager\Internal\LazyLoadingFactoryTrait; use Symfony\Bridge\ProxyManager\Internal\ProxyGenerator; @@ -43,18 +45,36 @@ public function __construct() */ public function instantiateProxy(ContainerInterface $container, Definition $definition, string $id, callable $realInstantiator): object { - $proxifiedClass = new \ReflectionClass($this->generator->getProxifiedClass($definition)); + $proxifiedClass = new \ReflectionClass($this->generator->getProxifiedClass($definition, $asGhostObject)); + $generator = $this->generator->asGhostObject($asGhostObject); - $factory = new class($this->config, $this->generator) extends LazyLoadingValueHolderFactory { - use LazyLoadingFactoryTrait; - }; + if ($asGhostObject) { + $factory = new class($this->config, $generator) extends LazyLoadingGhostFactory { + use LazyLoadingFactoryTrait; + }; - $initializer = static function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { - $wrappedInstance = $realInstantiator(); - $proxy->setProxyInitializer(null); + $initializer = static function (GhostObjectInterface $proxy, string $method, array $parameters, &$initializer, array $properties) use ($realInstantiator) { + $instance = $realInstantiator($proxy); + $initializer = null; - return true; - }; + if ($instance !== $proxy) { + throw new \LogicException(sprintf('A lazy initializer should return the ghost object proxy it was given as argument, but an instance of "%s" was returned.', get_debug_type($instance))); + } + + return true; + }; + } else { + $factory = new class($this->config, $generator) extends LazyLoadingValueHolderFactory { + use LazyLoadingFactoryTrait; + }; + + $initializer = static function (&$wrappedInstance, LazyLoadingInterface $proxy) use ($realInstantiator) { + $wrappedInstance = $realInstantiator(); + $proxy->setProxyInitializer(null); + + return true; + }; + } return $factory->createProxy($proxifiedClass->name, $initializer, [ 'fluentSafe' => $definition->hasTag('proxy'), diff --git a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php index 308a9c7854b47..b08616d9f5e51 100644 --- a/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php +++ b/src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php @@ -42,9 +42,7 @@ public function __construct(string $salt = '') */ public function isProxyCandidate(Definition $definition, bool &$asGhostObject = null): bool { - $asGhostObject = false; - - return ($definition->isLazy() || $definition->hasTag('proxy')) && $this->proxyGenerator->getProxifiedClass($definition); + return ($definition->isLazy() || $definition->hasTag('proxy')) && $this->proxyGenerator->getProxifiedClass($definition, $asGhostObject); } /** @@ -58,9 +56,30 @@ public function getProxyFactoryCode(Definition $definition, string $id, string $ $instantiation .= sprintf(' $this->%s[%s] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', var_export($id, true)); } - $proxifiedClass = new \ReflectionClass($this->proxyGenerator->getProxifiedClass($definition)); + $proxifiedClass = new \ReflectionClass($this->proxyGenerator->getProxifiedClass($definition, $asGhostObject)); $proxyClass = $this->getProxyClassName($proxifiedClass->name); + if ($asGhostObject) { + return <<createProxy('$proxyClass', function () { + return \\$proxyClass::staticProxyConstructor(function (\ProxyManager\Proxy\GhostObjectInterface \$proxy, string \$method, array \$parameters, &\$initializer, array \$properties) { + \$instance = $factoryCode; + \$initializer = null; + + if (\$instance !== \$proxy) { + throw new \LogicException(sprintf('A lazy initializer should return the ghost object proxy it was given as argument, but an instance of "%s" was returned.', get_debug_type(\$instance))); + } + + return true; + }); + }); + } + + +EOF; + } + return <<createProxy('$proxyClass', function () { @@ -96,10 +115,10 @@ private function getProxyClassName(string $class): string private function generateProxyClass(Definition $definition): ClassGenerator { - $class = $this->proxyGenerator->getProxifiedClass($definition); + $class = $this->proxyGenerator->getProxifiedClass($definition, $asGhostObject); $generatedClass = new ClassGenerator($this->getProxyClassName($class)); - $this->proxyGenerator->generate(new \ReflectionClass($class), $generatedClass, [ + $this->proxyGenerator->asGhostObject($asGhostObject)->generate(new \ReflectionClass($class), $generatedClass, [ 'fluentSafe' => $definition->hasTag('proxy'), 'skipDestructor' => true, ]); diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php index 69b7239655944..f1486f10864cd 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php @@ -14,7 +14,7 @@ require_once __DIR__.'/Fixtures/includes/foo.php'; use PHPUnit\Framework\TestCase; -use ProxyManager\Proxy\LazyLoadingInterface; +use ProxyManager\Proxy\GhostObjectInterface; use ProxyManagerBridgeFooClass; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -38,7 +38,7 @@ public function testCreateProxyServiceWithRuntimeInstantiator() $builder->compile(); - /* @var $foo1 \ProxyManager\Proxy\LazyLoadingInterface|\ProxyManager\Proxy\ValueHolderInterface */ + /* @var $foo1 \ProxyManager\Proxy\GhostObjectInterface */ $foo1 = $builder->get('foo1'); $foo1->__destruct(); @@ -46,15 +46,13 @@ public function testCreateProxyServiceWithRuntimeInstantiator() $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls'); $this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1); - $this->assertInstanceOf(LazyLoadingInterface::class, $foo1); + $this->assertInstanceOf(GhostObjectInterface::class, $foo1); $this->assertFalse($foo1->isProxyInitialized()); $foo1->initializeProxy(); $this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization'); $this->assertTrue($foo1->isProxyInitialized()); - $this->assertInstanceOf(ProxyManagerBridgeFooClass::class, $foo1->getWrappedValueHolderValue()); - $this->assertNotInstanceOf(LazyLoadingInterface::class, $foo1->getWrappedValueHolderValue()); $foo1->__destruct(); $this->assertSame(1, $foo1::$destructorCount); diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php index 8bc017bb8df71..f112234e998d1 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php @@ -12,7 +12,7 @@ namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper; use PHPUnit\Framework\TestCase; -use ProxyManager\Proxy\LazyLoadingInterface; +use ProxyManager\Proxy\GhostObjectInterface; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -47,7 +47,7 @@ public function testDumpContainerWithProxyServiceWillShareProxies() $proxy = $container->get('foo'); $this->assertInstanceOf(\stdClass::class, $proxy); - $this->assertInstanceOf(LazyLoadingInterface::class, $proxy); + $this->assertInstanceOf(GhostObjectInterface::class, $proxy); $this->assertSame($proxy, $container->get('foo')); $this->assertFalse($proxy->isProxyInitialized()); @@ -62,8 +62,10 @@ private function dumpLazyServiceProjectServiceContainer() { $container = new ContainerBuilder(); - $container->register('foo', 'stdClass')->setPublic(true); - $container->getDefinition('foo')->setLazy(true); + $container->register('foo', 'stdClass') + ->setPublic(true) + ->setLazy(true) + ->setProperty('bar', 123); $container->compile(); $dumper = new PhpDumper($container); diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt index 825c1051ca38f..4c9583f43bcfc 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Fixtures/php/lazy_service_structure.txt @@ -7,17 +7,24 @@ class LazyServiceProjectServiceContainer extends Container { if (true === $lazyLoad) { return $this->services['foo'] = $this->createProxy('stdClass_%s', function () { - return %S\stdClass_%s(function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) { - $wrappedInstance = $this->getFooService(false); + return \stdClass_%s::staticProxyConstructor(function (\ProxyManager\Proxy\GhostObjectInterface $proxy, string $method, array $parameters, &$initializer, array $properties) { + $instance = $this->getFooService($proxy); + $initializer = null; - $proxy->setProxyInitializer(null); + if ($instance !== $proxy) { + throw new \LogicException(sprintf('A lazy initializer should return the ghost object proxy it was given as argument, but an instance of "%s" was returned.', get_debug_type($instance))); + } return true; }); }); } - return new \stdClass(); + $instance = $lazyLoad; + + $instance->bar = 123; + + return $instance; } } diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php index e202fad702655..926c409e336e6 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Instantiator/RuntimeInstantiatorTest.php @@ -12,8 +12,7 @@ namespace Symfony\Bridge\ProxyManager\Tests\LazyProxy\Instantiator; use PHPUnit\Framework\TestCase; -use ProxyManager\Proxy\LazyLoadingInterface; -use ProxyManager\Proxy\ValueHolderInterface; +use ProxyManager\Proxy\GhostObjectInterface; use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; @@ -40,22 +39,19 @@ protected function setUp(): void public function testInstantiateProxy() { - $instance = new \stdClass(); $container = $this->createMock(ContainerInterface::class); $definition = new Definition('stdClass'); - $instantiator = function () use ($instance) { - return $instance; + $instantiator = function ($proxy) { + return $proxy; }; - /* @var $proxy LazyLoadingInterface|ValueHolderInterface */ + /* @var $proxy GhostObjectInterface */ $proxy = $this->instantiator->instantiateProxy($container, $definition, 'foo', $instantiator); - $this->assertInstanceOf(LazyLoadingInterface::class, $proxy); - $this->assertInstanceOf(ValueHolderInterface::class, $proxy); + $this->assertInstanceOf(GhostObjectInterface::class, $proxy); $this->assertFalse($proxy->isProxyInitialized()); $proxy->initializeProxy(); - - $this->assertSame($instance, $proxy->getWrappedValueHolderValue()); + $this->assertTrue($proxy->isProxyInitialized()); } } diff --git a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php index e787da909bbb3..f503e888c957d 100644 --- a/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php +++ b/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php @@ -72,6 +72,7 @@ public function testGetProxyFactoryCode() $definition = new Definition(__CLASS__); $definition->setLazy(true); + $definition->addTag('proxy', ['interface' => __CLASS__]); $code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)'); @@ -87,6 +88,7 @@ public function testGetProxyFactoryCode() public function testCorrectAssigning(Definition $definition, $access) { $definition->setLazy(true); + $definition->addTag('proxy', ['interface' => __CLASS__]); $code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)'); diff --git a/src/Symfony/Bridge/ProxyManager/composer.json b/src/Symfony/Bridge/ProxyManager/composer.json index d141f99ba6ee5..68bd922f2615d 100644 --- a/src/Symfony/Bridge/ProxyManager/composer.json +++ b/src/Symfony/Bridge/ProxyManager/composer.json @@ -18,11 +18,15 @@ "require": { "php": ">=8.1", "friendsofphp/proxy-manager-lts": "^1.0.2", - "symfony/dependency-injection": "^5.4|^6.0" + "symfony/dependency-injection": "^6.2", + "symfony/var-exporter": "^6.2" }, "require-dev": { "symfony/config": "^5.4|^6.0" }, + "conflict": { + "symfony/doctrine-bridge": "<6.2" + }, "autoload": { "psr-4": { "Symfony\\Bridge\\ProxyManager\\": "" }, "exclude-from-classmap": [ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt index 4de145af7177f..df1495502657b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_lazy_inlined_factories.txt @@ -6,7 +6,7 @@ namespace Container%s; include_once $this->targetDir.''.'/Fixtures/includes/foo.php'; -class FooClass_%s extends \Bar\FooClass implements \ProxyManager\Proxy\VirtualProxyInterface +class FooClass_%s extends \Bar\FooClass implements \ProxyManager\Proxy\GhostObjectInterface %A if (!\class_exists('FooClass_%s', false)) { @@ -88,10 +88,13 @@ class ProjectServiceContainer extends Container { if (true === $lazyLoad) { return $this->services['lazy_foo'] = $this->createProxy('FooClass_8976cfa', function () { - return \FooClass_8976cfa::staticProxyConstructor(function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) { - $wrappedInstance = $this->getLazyFooService(false); + return \FooClass_8976cfa::staticProxyConstructor(function (\ProxyManager\Proxy\GhostObjectInterface $proxy, string $method, array $parameters, &$initializer, array $properties) { + $instance = $this->getLazyFooService($proxy); + $initializer = null; - $proxy->setProxyInitializer(null); + if ($instance !== $proxy) { + throw new \LogicException(sprintf('A lazy initializer should return the ghost object proxy it was given as argument, but an instance of "%s" was returned.', get_debug_type($instance))); + } return true; }); @@ -100,7 +103,7 @@ class ProjectServiceContainer extends Container include_once $this->targetDir.''.'/Fixtures/includes/foo_lazy.php'; - return new \Bar\FooClass(new \Bar\FooLazyClass()); + return ($lazyLoad->__construct(new \Bar\FooLazyClass()) && false ?: $lazyLoad); } public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy