From fbd2b9608818b21cbda42d8fe9379234f47f9e65 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Thu, 29 May 2025 14:00:57 +0200 Subject: [PATCH 1/5] Replace get_class() calls by ::class --- Tests/Compiler/ServiceLocatorTagPassTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Compiler/ServiceLocatorTagPassTest.php b/Tests/Compiler/ServiceLocatorTagPassTest.php index 812b47c7a..7218db6de 100644 --- a/Tests/Compiler/ServiceLocatorTagPassTest.php +++ b/Tests/Compiler/ServiceLocatorTagPassTest.php @@ -83,7 +83,7 @@ public function testProcessValue() $this->assertSame(CustomDefinition::class, $locator('bar')::class); $this->assertSame(CustomDefinition::class, $locator('baz')::class); $this->assertSame(CustomDefinition::class, $locator('some.service')::class); - $this->assertSame(CustomDefinition::class, \get_class($locator('inlines.service'))); + $this->assertSame(CustomDefinition::class, $locator('inlines.service')::class); } public function testServiceWithKeyOverwritesPreviousInheritedKey() From b511363099bce8ec9e0729e2daa406d197bf68f9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 16:08:14 +0200 Subject: [PATCH 2/5] Allow Symfony ^8.0 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 460751088..7b1e731b7 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ "psr/container": "^1.1|^2.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^3.5", - "symfony/var-exporter": "^6.4.20|^7.2.5" + "symfony/var-exporter": "^6.4.20|^7.2.5|^8.0" }, "require-dev": { - "symfony/yaml": "^6.4|^7.0", - "symfony/config": "^6.4|^7.0", - "symfony/expression-language": "^6.4|^7.0" + "symfony/yaml": "^6.4|^7.0|^8.0", + "symfony/config": "^6.4|^7.0|^8.0", + "symfony/expression-language": "^6.4|^7.0|^8.0" }, "conflict": { "ext-psr": "<1.1|>=2", From 50b6b9772640ce6b9b31b291f8cca239f2aa6e4f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Jun 2025 17:50:55 +0200 Subject: [PATCH 3/5] Bump Symfony 8 to PHP >= 8.4 --- composer.json | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 7b1e731b7..86acbc6b7 100644 --- a/composer.json +++ b/composer.json @@ -16,22 +16,19 @@ } ], "require": { - "php": ">=8.2", + "php": ">=8.4", "psr/container": "^1.1|^2.0", "symfony/deprecation-contracts": "^2.5|^3", "symfony/service-contracts": "^3.5", - "symfony/var-exporter": "^6.4.20|^7.2.5|^8.0" + "symfony/var-exporter": "^7.4|^8.0" }, "require-dev": { - "symfony/yaml": "^6.4|^7.0|^8.0", - "symfony/config": "^6.4|^7.0|^8.0", - "symfony/expression-language": "^6.4|^7.0|^8.0" + "symfony/config": "^7.4|^8.0", + "symfony/expression-language": "^7.4|^8.0", + "symfony/yaml": "^7.4|^8.0" }, "conflict": { - "ext-psr": "<1.1|>=2", - "symfony/config": "<6.4", - "symfony/finder": "<6.4", - "symfony/yaml": "<6.4" + "ext-psr": "<1.1|>=2" }, "provide": { "psr/container-implementation": "1.1|2.0", From 81988917b80c9e7d23506c4e0420cea78699e1df Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 3 Jun 2025 17:41:25 +0200 Subject: [PATCH 4/5] Remove deadcode after the bump to PHP >= 8.4 --- .../Instantiator/LazyServiceInstantiator.php | 8 +- LazyProxy/PhpDumper/LazyServiceDumper.php | 37 +--- Tests/ContainerBuilderTest.php | 6 +- Tests/Dumper/PhpDumperTest.php | 77 ++----- .../php/legacy_lazy_autowire_attribute.php | 99 --------- ...y_autowire_attribute_with_intersection.php | 94 --------- ...egacy_services9_lazy_inlined_factories.txt | 196 ------------------ .../php/legacy_services_dedup_lazy.php | 126 ----------- .../php/legacy_services_non_shared_lazy.php | 76 ------- ...gacy_services_non_shared_lazy_as_files.txt | 173 ---------------- .../legacy_services_non_shared_lazy_ghost.php | 88 -------- ...legacy_services_non_shared_lazy_public.php | 81 -------- .../php/legacy_services_wither_lazy.php | 86 -------- ...legacy_services_wither_lazy_non_shared.php | 88 -------- .../PhpDumper/LazyServiceDumperTest.php | 5 +- 15 files changed, 27 insertions(+), 1213 deletions(-) delete mode 100644 Tests/Fixtures/php/legacy_lazy_autowire_attribute.php delete mode 100644 Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php delete mode 100644 Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt delete mode 100644 Tests/Fixtures/php/legacy_services_dedup_lazy.php delete mode 100644 Tests/Fixtures/php/legacy_services_non_shared_lazy.php delete mode 100644 Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt delete mode 100644 Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php delete mode 100644 Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php delete mode 100644 Tests/Fixtures/php/legacy_services_wither_lazy.php delete mode 100644 Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php diff --git a/LazyProxy/Instantiator/LazyServiceInstantiator.php b/LazyProxy/Instantiator/LazyServiceInstantiator.php index 107482562..77b3def32 100644 --- a/LazyProxy/Instantiator/LazyServiceInstantiator.php +++ b/LazyProxy/Instantiator/LazyServiceInstantiator.php @@ -29,12 +29,12 @@ public function instantiateProxy(ContainerInterface $container, Definition $defi throw new InvalidArgumentException(\sprintf('Cannot instantiate lazy proxy for service "%s".', $id)); } - if (\PHP_VERSION_ID >= 80400 && $asGhostObject) { - return (new \ReflectionClass($definition->getClass()))->newLazyGhost(static function ($ghost) use ($realInstantiator) { $realInstantiator($ghost); }); + if ($asGhostObject) { + return new \ReflectionClass($definition->getClass())->newLazyGhost(static function ($ghost) use ($realInstantiator) { $realInstantiator($ghost); }); } $class = null; - if (!class_exists($proxyClass = $dumper->getProxyClass($definition, $asGhostObject, $class), false)) { + if (!class_exists($proxyClass = $dumper->getProxyClass($definition, false, $class), false)) { eval($dumper->getProxyCode($definition, $id)); } @@ -42,6 +42,6 @@ public function instantiateProxy(ContainerInterface $container, Definition $defi return $class->newLazyProxy($realInstantiator); } - return \PHP_VERSION_ID < 80400 && $asGhostObject ? $proxyClass::createLazyGhost($realInstantiator) : $proxyClass::createLazyProxy($realInstantiator); + return $proxyClass::createLazyProxy($realInstantiator); } } diff --git a/LazyProxy/PhpDumper/LazyServiceDumper.php b/LazyProxy/PhpDumper/LazyServiceDumper.php index 0933c1a59..2aefe78b0 100644 --- a/LazyProxy/PhpDumper/LazyServiceDumper.php +++ b/LazyProxy/PhpDumper/LazyServiceDumper.php @@ -56,15 +56,6 @@ public function isProxyCandidate(Definition $definition, ?bool &$asGhostObject = } } - if (\PHP_VERSION_ID < 80400) { - try { - $asGhostObject = (bool) ProxyHelper::generateLazyGhost(new \ReflectionClass($class)); - } catch (LogicException) { - } - - return true; - } - try { $asGhostObject = (bool) (new \ReflectionClass($class))->newLazyGhost(static fn () => null); } catch (\Error $e) { @@ -107,18 +98,6 @@ public function getProxyFactoryCode(Definition $definition, string $id, string $ EOF; } - if (\PHP_VERSION_ID < 80400) { - $factoryCode = \sprintf('static fn ($proxy) => %s', $factoryCode); - - return <<createProxy('$proxyClass', static fn () => \\$proxyClass::createLazyGhost($factoryCode)); - } - - - EOF; - } - $factoryCode = \sprintf('static function ($proxy) use ($container) { %s; }', $factoryCode); return <<getProxyClass($definition, $asGhostObject, $class); if ($asGhostObject) { - if (\PHP_VERSION_ID >= 80400) { - return ''; - } - - try { - return ($class?->isReadOnly() ? 'readonly ' : '').'class '.$proxyClass.ProxyHelper::generateLazyGhost($class); - } catch (LogicException $e) { - throw new InvalidArgumentException(\sprintf('Cannot generate lazy ghost for service "%s".', $id ?? $definition->getClass()), 0, $e); - } + return ''; } if ($definition->getClass() === $proxyClass) { @@ -187,12 +158,6 @@ public function getProxyClass(Definition $definition, bool $asGhostObject, ?\Ref $class = 'object' !== $definition->getClass() ? $definition->getClass() : 'stdClass'; $class = new \ReflectionClass($class); - if (\PHP_VERSION_ID < 80400) { - return preg_replace('/^.*\\\\/', '', $definition->getClass()) - .($asGhostObject ? 'Ghost' : 'Proxy') - .ucfirst(substr(hash('xxh128', $this->salt.'+'.$class->name.'+'.serialize($definition->getTag('proxy'))), -7)); - } - if ($asGhostObject) { return $class->name; } diff --git a/Tests/ContainerBuilderTest.php b/Tests/ContainerBuilderTest.php index 774b1f88b..8360cc367 100644 --- a/Tests/ContainerBuilderTest.php +++ b/Tests/ContainerBuilderTest.php @@ -1951,11 +1951,7 @@ public function testLazyWither() $container->compile(); $wither = $container->get('wither'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($wither))->isUninitializedLazyObject($wither)); - } else { - $this->assertTrue($wither->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($wither))->isUninitializedLazyObject($wither)); $this->assertInstanceOf(Foo::class, $wither->foo); $this->assertInstanceOf(Wither::class, $wither->withFoo1($wither->foo)); } diff --git a/Tests/Dumper/PhpDumperTest.php b/Tests/Dumper/PhpDumperTest.php index a117a69a0..9b41b2776 100644 --- a/Tests/Dumper/PhpDumperTest.php +++ b/Tests/Dumper/PhpDumperTest.php @@ -340,7 +340,7 @@ public function testDumpAsFilesWithLazyFactoriesInlined() if ('\\' === \DIRECTORY_SEPARATOR) { $dump = str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump); } - $this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services9_lazy_inlined_factories.txt', $dump); + $this->assertStringMatchesFormatFile(self::$fixturesPath.'/php/services9_lazy_inlined_factories.txt', $dump); } public function testServicesWithAnonymousFactories() @@ -794,7 +794,7 @@ public function testNonSharedLazy() 'inline_class_loader' => false, ]); $this->assertStringEqualsFile( - self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_non_shared_lazy_public.php', + self::$fixturesPath.'/php/services_non_shared_lazy_public.php', '\\' === \DIRECTORY_SEPARATOR ? str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $dump) : $dump ); eval('?>'.$dump); @@ -802,18 +802,10 @@ public function testNonSharedLazy() $container = new \Symfony_DI_PhpDumper_Service_Non_Shared_Lazy(); $foo1 = $container->get('foo'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($foo1))->isUninitializedLazyObject($foo1)); - } else { - $this->assertTrue($foo1->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($foo1))->isUninitializedLazyObject($foo1)); $foo2 = $container->get('foo'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($foo2))->isUninitializedLazyObject($foo2)); - } else { - $this->assertTrue($foo2->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($foo2))->isUninitializedLazyObject($foo2)); $this->assertNotSame($foo1, $foo2); } @@ -840,7 +832,7 @@ public function testNonSharedLazyAsFiles() $stringDump = print_r($dumps, true); $this->assertStringMatchesFormatFile( - self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_non_shared_lazy_as_files.txt', + self::$fixturesPath.'/php/services_non_shared_lazy_as_files.txt', '\\' === \DIRECTORY_SEPARATOR ? str_replace("'.\\DIRECTORY_SEPARATOR.'", '/', $stringDump) : $stringDump ); @@ -852,18 +844,10 @@ public function testNonSharedLazyAsFiles() $container = eval('?>'.$lastDump); $foo1 = $container->get('non_shared_foo'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($foo1))->isUninitializedLazyObject($foo1)); - } else { - $this->assertTrue($foo1->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($foo1))->isUninitializedLazyObject($foo1)); $foo2 = $container->get('non_shared_foo'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($foo2))->isUninitializedLazyObject($foo2)); - } else { - $this->assertTrue($foo2->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($foo2))->isUninitializedLazyObject($foo2)); $this->assertNotSame($foo1, $foo2); } @@ -885,7 +869,7 @@ public function testNonSharedLazyDefinitionReferences(bool $asGhostObject) $dumper->setProxyDumper(new \DummyProxyDumper()); } - $this->assertStringEqualsFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_non_shared_lazy'.($asGhostObject ? '_ghost' : '').'.php', $dumper->dump()); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_non_shared_lazy'.($asGhostObject ? '_ghost' : '').'.php', $dumper->dump()); } public function testNonSharedDuplicates() @@ -958,7 +942,7 @@ public function testDedupLazyProxy() $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_dedup_lazy.php', $dumper->dump()); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_dedup_lazy.php', $dumper->dump()); } public function testLazyArgumentProvideGenerator() @@ -1623,17 +1607,13 @@ public function testLazyWither() $container->compile(); $dumper = new PhpDumper($container); $dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_Wither_Lazy']); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_wither_lazy.php', $dump); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_lazy.php', $dump); eval('?>'.$dump); $container = new \Symfony_DI_PhpDumper_Service_Wither_Lazy(); $wither = $container->get('wither'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($wither))->isUninitializedLazyObject($wither)); - } else { - $this->assertTrue($wither->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($wither))->isUninitializedLazyObject($wither)); $this->assertInstanceOf(Foo::class, $wither->foo); } @@ -1652,25 +1632,17 @@ public function testLazyWitherNonShared() $container->compile(); $dumper = new PhpDumper($container); $dump = $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared']); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'services_wither_lazy_non_shared.php', $dump); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/services_wither_lazy_non_shared.php', $dump); eval('?>'.$dump); $container = new \Symfony_DI_PhpDumper_Service_Wither_Lazy_Non_Shared(); $wither1 = $container->get('wither'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($wither1))->isUninitializedLazyObject($wither1)); - } else { - $this->assertTrue($wither1->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($wither1))->isUninitializedLazyObject($wither1)); $this->assertInstanceOf(Foo::class, $wither1->foo); $wither2 = $container->get('wither'); - if (\PHP_VERSION_ID >= 80400) { - $this->assertTrue((new \ReflectionClass($wither2))->isUninitializedLazyObject($wither2)); - } else { - $this->assertTrue($wither2->resetLazyObject()); - } + $this->assertTrue((new \ReflectionClass($wither2))->isUninitializedLazyObject($wither2)); $this->assertInstanceOf(Foo::class, $wither2->foo); $this->assertNotSame($wither1, $wither2); @@ -1999,21 +1971,16 @@ public function testLazyAutowireAttribute() $container->compile(); $dumper = new PhpDumper($container); - $this->assertStringEqualsFile(self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'lazy_autowire_attribute.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute'])); + $this->assertStringEqualsFile(self::$fixturesPath.'/php/lazy_autowire_attribute.php', $dumper->dump(['class' => 'Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute'])); - require self::$fixturesPath.'/php/'.(\PHP_VERSION_ID < 80400 ? 'legacy_' : '').'lazy_autowire_attribute.php'; + require self::$fixturesPath.'/php/lazy_autowire_attribute.php'; $container = new \Symfony_DI_PhpDumper_Test_Lazy_Autowire_Attribute(); $this->assertInstanceOf(Foo::class, $container->get('bar')->foo); - if (\PHP_VERSION_ID >= 80400) { - $r = new \ReflectionClass(Foo::class); - $this->assertTrue($r->isUninitializedLazyObject($container->get('bar')->foo)); - $this->assertSame($container->get('foo'), $r->initializeLazyObject($container->get('bar')->foo)); - } else { - $this->assertInstanceOf(LazyObjectInterface::class, $container->get('bar')->foo); - $this->assertSame($container->get('foo'), $container->get('bar')->foo->initializeLazyObject()); - } + $r = new \ReflectionClass(Foo::class); + $this->assertTrue($r->isUninitializedLazyObject($container->get('bar')->foo)); + $this->assertSame($container->get('foo'), $r->initializeLazyObject($container->get('bar')->foo)); } public function testLazyAutowireAttributeWithIntersection() @@ -2036,11 +2003,7 @@ public function testLazyAutowireAttributeWithIntersection() $dumper = new PhpDumper($container); - if (\PHP_VERSION_ID >= 80400) { - $this->assertStringEqualsFile(self::$fixturesPath.'/php/lazy_autowire_attribute_with_intersection.php', $dumper->dump()); - } else { - $this->assertStringEqualsFile(self::$fixturesPath.'/php/legacy_lazy_autowire_attribute_with_intersection.php', $dumper->dump()); - } + $this->assertStringEqualsFile(self::$fixturesPath.'/php/lazy_autowire_attribute_with_intersection.php', $dumper->dump()); } public function testCallableAdapterConsumer() diff --git a/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php b/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php deleted file mode 100644 index 6cf1c86a5..000000000 --- a/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php +++ /dev/null @@ -1,99 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'bar' => 'getBarService', - 'foo' => 'getFooService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - public function getRemovedIds(): array - { - return [ - 'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true, - ]; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'bar' shared autowired service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Dumper\LazyServiceConsumer - */ - protected static function getBarService($container) - { - return $container->services['bar'] = new \Symfony\Component\DependencyInjection\Tests\Dumper\LazyServiceConsumer(($container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ?? self::getFoo2Service($container))); - } - - /** - * Gets the public 'foo' shared service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo - */ - protected static function getFooService($container) - { - return $container->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo(); - } - - /** - * Gets the private '.lazy.Symfony\Component\DependencyInjection\Tests\Compiler\Foo' shared service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Foo - */ - protected static function getFoo2Service($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->privates['.lazy.Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] = $container->createProxy('FooProxyCd8d23a', static fn () => \FooProxyCd8d23a::createLazyProxy(static fn () => self::getFoo2Service($container, false))); - } - - return ($container->services['foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo()); - } -} - -class FooProxyCd8d23a extends \Symfony\Component\DependencyInjection\Tests\Compiler\Foo implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null, 4], - ]; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php b/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php deleted file mode 100644 index fcf66ad12..000000000 --- a/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php +++ /dev/null @@ -1,94 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'foo' => 'getFooService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'foo' shared autowired service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Compiler\AAndIInterfaceConsumer - */ - protected static function getFooService($container) - { - $a = ($container->privates['.lazy.foo.qFdMZVK'] ?? self::get_Lazy_Foo_QFdMZVKService($container)); - - if (isset($container->services['foo'])) { - return $container->services['foo']; - } - - return $container->services['foo'] = new \Symfony\Component\DependencyInjection\Tests\Compiler\AAndIInterfaceConsumer($a); - } - - /** - * Gets the private '.lazy.foo.qFdMZVK' shared service. - * - * @return \object - */ - protected static function get_Lazy_Foo_QFdMZVKService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->privates['.lazy.foo.qFdMZVK'] = $container->createProxy('objectProxy1fd6daa', static fn () => \objectProxy1fd6daa::createLazyProxy(static fn () => self::get_Lazy_Foo_QFdMZVKService($container, false))); - } - - return ($container->services['foo'] ?? self::getFooService($container)); - } -} - -class objectProxy1fd6daa implements \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface, \Symfony\Component\DependencyInjection\Tests\Compiler\IInterface, \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; - - public function initializeLazyObject(): \Symfony\Component\DependencyInjection\Tests\Compiler\AInterface&\Symfony\Component\DependencyInjection\Tests\Compiler\IInterface - { - if ($state = $this->lazyObjectState ?? null) { - return $state->realInstance ??= ($state->initializer)(); - } - - return $this; - } -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt b/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt deleted file mode 100644 index f945fdd50..000000000 --- a/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt +++ /dev/null @@ -1,196 +0,0 @@ -Array -( - [Container%s/proxy-classes.php] => targetDir.''.'/Fixtures/includes/foo.php'; - -class FooClassGhost1728205 extends \Bar\FooClass implements \Symfony\Component\VarExporter\LazyObjectInterface -%A - -if (!\class_exists('FooClassGhost1728205', false)) { - \class_alias(__NAMESPACE__.'\\FooClassGhost1728205', 'FooClassGhost1728205', false); -} - - [Container%s/ProjectServiceContainer.php] => targetDir = \dirname($containerDir); - $this->parameters = $this->getDefaultParameters(); - - $this->services = $this->privates = []; - $this->methodMap = [ - 'lazy_foo' => 'getLazyFooService', - ]; - - $this->aliases = []; - - $this->privates['service_container'] = static function ($container) { - include_once __DIR__.'/proxy-classes.php'; - }; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'lazy_foo' shared service. - * - * @return \Bar\FooClass - */ - protected static function getLazyFooService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['lazy_foo'] = $container->createProxy('FooClassGhost1728205', static fn () => \FooClassGhost1728205::createLazyGhost(static fn ($proxy) => self::getLazyFooService($container, $proxy))); - } - - include_once $container->targetDir.''.'/Fixtures/includes/foo_lazy.php'; - - return ($lazyLoad->__construct(new \Bar\FooLazyClass()) && false ?: $lazyLoad); - } - - public function getParameter(string $name): array|bool|string|int|float|\UnitEnum|null - { - if (isset($this->buildParameters[$name])) { - return $this->buildParameters[$name]; - } - - if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || \array_key_exists($name, $this->parameters))) { - throw new ParameterNotFoundException($name); - } - - if (isset($this->loadedDynamicParameters[$name])) { - $value = $this->loadedDynamicParameters[$name] ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); - } else { - $value = $this->parameters[$name]; - } - - return $value; - } - - public function hasParameter(string $name): bool - { - if (isset($this->buildParameters[$name])) { - return true; - } - - return isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || \array_key_exists($name, $this->parameters); - } - - public function setParameter(string $name, $value): void - { - throw new LogicException('Impossible to call set() on a frozen ParameterBag.'); - } - - public function getParameterBag(): ParameterBagInterface - { - if (!isset($this->parameterBag)) { - $parameters = $this->parameters; - foreach ($this->loadedDynamicParameters as $name => $loaded) { - $parameters[$name] = $loaded ? $this->dynamicParameters[$name] : $this->getDynamicParameter($name); - } - foreach ($this->buildParameters as $name => $value) { - $parameters[$name] = $value; - } - $this->parameterBag = new FrozenParameterBag($parameters, []); - } - - return $this->parameterBag; - } - - private $loadedDynamicParameters = []; - private $dynamicParameters = []; - - private function getDynamicParameter(string $name) - { - throw new ParameterNotFoundException($name); - } - - protected function getDefaultParameters(): array - { - return [ - 'lazy_foo_class' => 'Bar\\FooClass', - 'container.dumper.inline_factories' => true, - 'container.dumper.inline_class_loader' => true, - ]; - } -} - - [ProjectServiceContainer.preload.php] => = 7.4 when preloading is desired - -use Symfony\Component\DependencyInjection\Dumper\Preloader; - -if (in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { - return; -} - -require dirname(__DIR__, %d).'%svendor/autoload.php'; -(require __DIR__.'/ProjectServiceContainer.php')->set(\Container%s\ProjectServiceContainer::class, null); - -$classes = []; -$classes[] = 'Bar\FooClass'; -$classes[] = 'Bar\FooLazyClass'; -$classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface'; - -$preloaded = Preloader::preload($classes); - - [ProjectServiceContainer.php] => '%s', - 'container.build_id' => '%s', - 'container.build_time' => 1563381341, - 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', -], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); - -) diff --git a/Tests/Fixtures/php/legacy_services_dedup_lazy.php b/Tests/Fixtures/php/legacy_services_dedup_lazy.php deleted file mode 100644 index 60add492b..000000000 --- a/Tests/Fixtures/php/legacy_services_dedup_lazy.php +++ /dev/null @@ -1,126 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'bar' => 'getBarService', - 'baz' => 'getBazService', - 'buz' => 'getBuzService', - 'foo' => 'getFooService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'bar' shared service. - * - * @return \stdClass - */ - protected static function getBarService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['bar'] = $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getBarService($container, $proxy))); - } - - return $lazyLoad; - } - - /** - * Gets the public 'baz' shared service. - * - * @return \stdClass - */ - protected static function getBazService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['baz'] = $container->createProxy('stdClassProxyAa01f12', static fn () => \stdClassProxyAa01f12::createLazyProxy(static fn () => self::getBazService($container, false))); - } - - return \foo_bar(); - } - - /** - * Gets the public 'buz' shared service. - * - * @return \stdClass - */ - protected static function getBuzService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['buz'] = $container->createProxy('stdClassProxyAa01f12', static fn () => \stdClassProxyAa01f12::createLazyProxy(static fn () => self::getBuzService($container, false))); - } - - return \foo_bar(); - } - - /** - * Gets the public 'foo' shared service. - * - * @return \stdClass - */ - protected static function getFooService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['foo'] = $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy))); - } - - return $lazyLoad; - } -} - -class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyGhostTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); - -class stdClassProxyAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_services_non_shared_lazy.php b/Tests/Fixtures/php/legacy_services_non_shared_lazy.php deleted file mode 100644 index f584bef6b..000000000 --- a/Tests/Fixtures/php/legacy_services_non_shared_lazy.php +++ /dev/null @@ -1,76 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'bar' => 'getBarService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - public function getRemovedIds(): array - { - return [ - 'foo' => true, - ]; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'bar' shared service. - * - * @return \stdClass - */ - protected static function getBarService($container) - { - return $container->services['bar'] = new \stdClass((isset($container->factories['service_container']['foo']) ? $container->factories['service_container']['foo']($container) : self::getFooService($container))); - } - - /** - * Gets the private 'foo' service. - * - * @return \stdClass - */ - protected static function getFooService($container, $lazyLoad = true) - { - $container->factories['service_container']['foo'] ??= self::getFooService(...); - - // lazy factory for stdClass - - return new \stdClass(); - } -} - -// proxy code for stdClass diff --git a/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt b/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt deleted file mode 100644 index d52dd5a7b..000000000 --- a/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt +++ /dev/null @@ -1,173 +0,0 @@ -Array -( - [Container%s/getNonSharedFooService.php] => factories['non_shared_foo'] ??= fn () => self::do($container); - - if (true === $lazyLoad) { - return $container->createProxy('FooLazyClassGhost%s', static fn () => \FooLazyClassGhost%s::createLazyGhost(static fn ($proxy) => self::do($container, $proxy))); - } - - static $include = true; - - if ($include) { - include_once '%sfoo_lazy.php'; - - $include = false; - } - - return $lazyLoad; - } -} - - [Container%s/FooLazyClassGhost%s.php] => [parent::class, 'foo', null, 4], - ]; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); - -if (!\class_exists('FooLazyClassGhost%s', false)) { - \class_alias(__NAMESPACE__.'\\FooLazyClassGhost%s', 'FooLazyClassGhost%s', false); -} - - [Container%s/Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File.php] => services = $this->privates = []; - $this->fileMap = [ - 'non_shared_foo' => 'getNonSharedFooService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - protected function load($file, $lazyLoad = true): mixed - { - if (class_exists($class = __NAMESPACE__.'\\'.$file, false)) { - return $class::do($this, $lazyLoad); - } - - if ('.' === $file[-4]) { - $class = substr($class, 0, -4); - } else { - $file .= '.php'; - } - - $service = require $this->containerDir.\DIRECTORY_SEPARATOR.$file; - - return class_exists($class, false) ? $class::do($this, $lazyLoad) : $service; - } - - protected function createProxy($class, \Closure $factory) - { - class_exists($class, false) || require __DIR__.'/'.$class.'.php'; - - return $factory(); - } -} - - [Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File.preload.php] => = 7.4 when preloading is desired - -use Symfony\Component\DependencyInjection\Dumper\Preloader; - -if (in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { - return; -} - -require '%svendor/autoload.php'; -(require __DIR__.'/Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File.php')->set(\Container%s\Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File::class, null); -require __DIR__.'/Container%s/FooLazyClassGhost%s.php'; -require __DIR__.'/Container%s/getNonSharedFooService.php'; - -$classes = []; -$classes[] = 'Bar\FooLazyClass'; -$classes[] = 'Symfony\Component\DependencyInjection\ContainerInterface'; - -$preloaded = Preloader::preload($classes); - - [Symfony_DI_PhpDumper_Service_Non_Shared_Lazy_As_File.php] => '%s', - 'container.build_id' => '%s', - 'container.build_time' => %d, - 'container.runtime_mode' => \in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'web=0' : 'web=1', -], __DIR__.\DIRECTORY_SEPARATOR.'Container%s'); - -) diff --git a/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php b/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php deleted file mode 100644 index b03463295..000000000 --- a/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php +++ /dev/null @@ -1,88 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'bar' => 'getBarService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - public function getRemovedIds(): array - { - return [ - 'foo' => true, - ]; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'bar' shared service. - * - * @return \stdClass - */ - protected static function getBarService($container) - { - return $container->services['bar'] = new \stdClass((isset($container->factories['service_container']['foo']) ? $container->factories['service_container']['foo']($container) : self::getFooService($container))); - } - - /** - * Gets the private 'foo' service. - * - * @return \stdClass - */ - protected static function getFooService($container, $lazyLoad = true) - { - $container->factories['service_container']['foo'] ??= self::getFooService(...); - - if (true === $lazyLoad) { - return $container->createProxy('stdClassGhostAa01f12', static fn () => \stdClassGhostAa01f12::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy))); - } - - return $lazyLoad; - } -} - -class stdClassGhostAa01f12 extends \stdClass implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyGhostTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php b/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php deleted file mode 100644 index 0841cf192..000000000 --- a/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php +++ /dev/null @@ -1,81 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'foo' => 'getFooService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'foo' service. - * - * @return \Bar\FooLazyClass - */ - protected static function getFooService($container, $lazyLoad = true) - { - $container->factories['foo'] ??= fn () => self::getFooService($container); - - if (true === $lazyLoad) { - return $container->createProxy('FooLazyClassGhost82ad1a4', static fn () => \FooLazyClassGhost82ad1a4::createLazyGhost(static fn ($proxy) => self::getFooService($container, $proxy))); - } - - static $include = true; - - if ($include) { - include_once __DIR__.'/Fixtures/includes/foo_lazy.php'; - - $include = false; - } - - return $lazyLoad; - } -} - -class FooLazyClassGhost82ad1a4 extends \Bar\FooLazyClass implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyGhostTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null, 4], - ]; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_services_wither_lazy.php b/Tests/Fixtures/php/legacy_services_wither_lazy.php deleted file mode 100644 index b9e916457..000000000 --- a/Tests/Fixtures/php/legacy_services_wither_lazy.php +++ /dev/null @@ -1,86 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'wither' => 'getWitherService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - public function getRemovedIds(): array - { - return [ - 'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true, - ]; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'wither' shared autowired service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Wither - */ - protected static function getWitherService($container, $lazyLoad = true) - { - if (true === $lazyLoad) { - return $container->services['wither'] = $container->createProxy('WitherProxy1991f2a', static fn () => \WitherProxy1991f2a::createLazyProxy(static fn () => self::getWitherService($container, false))); - } - - $instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither(); - - $a = ($container->privates['Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo()); - - $instance = $instance->withFoo1($a); - $instance = $instance->withFoo2($a); - $instance->setFoo($a); - - return $instance; - } -} - -class WitherProxy1991f2a extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null, 4], - ]; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php b/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php deleted file mode 100644 index d70588f65..000000000 --- a/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php +++ /dev/null @@ -1,88 +0,0 @@ -services = $this->privates = []; - $this->methodMap = [ - 'wither' => 'getWitherService', - ]; - - $this->aliases = []; - } - - public function compile(): void - { - throw new LogicException('You cannot compile a dumped container that was already compiled.'); - } - - public function isCompiled(): bool - { - return true; - } - - public function getRemovedIds(): array - { - return [ - 'Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo' => true, - ]; - } - - protected function createProxy($class, \Closure $factory) - { - return $factory(); - } - - /** - * Gets the public 'wither' autowired service. - * - * @return \Symfony\Component\DependencyInjection\Tests\Compiler\Wither - */ - protected static function getWitherService($container, $lazyLoad = true) - { - $container->factories['wither'] ??= fn () => self::getWitherService($container); - - if (true === $lazyLoad) { - return $container->createProxy('WitherProxyE94fdba', static fn () => \WitherProxyE94fdba::createLazyProxy(static fn () => self::getWitherService($container, false))); - } - - $instance = new \Symfony\Component\DependencyInjection\Tests\Compiler\Wither(); - - $a = ($container->privates['Symfony\\Component\\DependencyInjection\\Tests\\Compiler\\Foo'] ??= new \Symfony\Component\DependencyInjection\Tests\Compiler\Foo()); - - $instance = $instance->withFoo1($a); - $instance = $instance->withFoo2($a); - $instance->setFoo($a); - - return $instance; - } -} - -class WitherProxyE94fdba extends \Symfony\Component\DependencyInjection\Tests\Compiler\Wither implements \Symfony\Component\VarExporter\LazyObjectInterface -{ - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = [ - 'foo' => [parent::class, 'foo', null, 4], - ]; -} - -// Help opcache.preload discover always-needed symbols -class_exists(\Symfony\Component\VarExporter\Internal\Hydrator::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); -class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectState::class); diff --git a/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php b/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php index 14d2f81b6..a0614c8c7 100644 --- a/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php +++ b/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php @@ -54,16 +54,13 @@ public function testInvalidClass() $dumper->getProxyCode($definition); } - /** - * @requires PHP 8.3 - */ public function testReadonlyClass() { $dumper = new LazyServiceDumper(); $definition = (new Definition(ReadOnlyClass::class))->setLazy(true); $this->assertTrue($dumper->isProxyCandidate($definition)); - $this->assertStringContainsString(\PHP_VERSION_ID >= 80400 ? '' : 'readonly class ReadOnlyClassGhost', $dumper->getProxyCode($definition)); + $this->assertStringContainsString('', $dumper->getProxyCode($definition)); } } From a92acfd53b02fd2aead2d5a6faa060d31c3e072a Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 4 Jun 2025 18:31:05 +0200 Subject: [PATCH 5/5] Enforce return types on all components --- Compiler/AbstractRecursivePass.php | 9 ++------- Compiler/CompilerPassInterface.php | 4 +--- Extension/ConfigurationExtensionInterface.php | 7 +------ Extension/Extension.php | 15 +++------------ Extension/ExtensionInterface.php | 16 ++++------------ Extension/PrependExtensionInterface.php | 4 +--- 6 files changed, 12 insertions(+), 43 deletions(-) diff --git a/Compiler/AbstractRecursivePass.php b/Compiler/AbstractRecursivePass.php index 55f8ee7e9..aeff6c14c 100644 --- a/Compiler/AbstractRecursivePass.php +++ b/Compiler/AbstractRecursivePass.php @@ -34,10 +34,7 @@ abstract class AbstractRecursivePass implements CompilerPassInterface private ExpressionLanguage $expressionLanguage; private bool $inExpression = false; - /** - * @return void - */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { $this->container = $container; @@ -65,10 +62,8 @@ protected function inExpression(bool $reset = true): bool /** * Processes a value found in a definition tree. - * - * @return mixed */ - protected function processValue(mixed $value, bool $isRoot = false) + protected function processValue(mixed $value, bool $isRoot = false): mixed { if (\is_array($value)) { foreach ($value as $k => $v) { diff --git a/Compiler/CompilerPassInterface.php b/Compiler/CompilerPassInterface.php index 2ad4a048b..d7ac4766f 100644 --- a/Compiler/CompilerPassInterface.php +++ b/Compiler/CompilerPassInterface.php @@ -22,8 +22,6 @@ interface CompilerPassInterface { /** * You can modify the container here before it is dumped to PHP code. - * - * @return void */ - public function process(ContainerBuilder $container); + public function process(ContainerBuilder $container): void; } diff --git a/Extension/ConfigurationExtensionInterface.php b/Extension/ConfigurationExtensionInterface.php index a42967f4d..3e99a77c1 100644 --- a/Extension/ConfigurationExtensionInterface.php +++ b/Extension/ConfigurationExtensionInterface.php @@ -21,10 +21,5 @@ */ interface ConfigurationExtensionInterface { - /** - * Returns extension configuration. - * - * @return ConfigurationInterface|null - */ - public function getConfiguration(array $config, ContainerBuilder $container); + public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface; } diff --git a/Extension/Extension.php b/Extension/Extension.php index 03d08d6d6..e804fbc57 100644 --- a/Extension/Extension.php +++ b/Extension/Extension.php @@ -28,18 +28,12 @@ abstract class Extension implements ExtensionInterface, ConfigurationExtensionIn { private array $processedConfigs = []; - /** - * @return string|false - */ - public function getXsdValidationBasePath() + public function getXsdValidationBasePath(): string|false { return false; } - /** - * @return string - */ - public function getNamespace() + public function getNamespace(): string { return 'http://example.org/schema/dic/'.$this->getAlias(); } @@ -73,10 +67,7 @@ public function getAlias(): string return Container::underscore($classBaseName); } - /** - * @return ConfigurationInterface|null - */ - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface { $class = static::class; diff --git a/Extension/ExtensionInterface.php b/Extension/ExtensionInterface.php index bd57eef73..5bd7a4d13 100644 --- a/Extension/ExtensionInterface.php +++ b/Extension/ExtensionInterface.php @@ -25,32 +25,24 @@ interface ExtensionInterface * * @param array> $configs * - * @return void - * * @throws \InvalidArgumentException When provided tag is not defined in this extension */ - public function load(array $configs, ContainerBuilder $container); + public function load(array $configs, ContainerBuilder $container): void; /** * Returns the namespace to be used for this extension (XML namespace). - * - * @return string */ - public function getNamespace(); + public function getNamespace(): string; /** * Returns the base path for the XSD files. - * - * @return string|false */ - public function getXsdValidationBasePath(); + public function getXsdValidationBasePath(): string|false; /** * Returns the recommended alias to use in XML. * * This alias is also the mandatory prefix to use when using YAML. - * - * @return string */ - public function getAlias(); + public function getAlias(): string; } diff --git a/Extension/PrependExtensionInterface.php b/Extension/PrependExtensionInterface.php index 0df94e109..89a40dcc7 100644 --- a/Extension/PrependExtensionInterface.php +++ b/Extension/PrependExtensionInterface.php @@ -17,8 +17,6 @@ interface PrependExtensionInterface { /** * Allow an extension to prepend the extension configurations. - * - * @return void */ - public function prepend(ContainerBuilder $container); + public function prepend(ContainerBuilder $container): void; }