From 13706ddb7e70946050cf95fdd975359d5927c466 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 3 Jun 2025 17:41:25 +0200 Subject: [PATCH] Remove deadcode after the bump to PHP >= 8.4 --- .../Bridge/Doctrine/ManagerRegistry.php | 30 --- .../Security/User/EntityUserProvider.php | 2 +- .../Doctrine/Tests/DoctrineTestHelper.php | 2 +- .../Doctrine/Tests/ManagerRegistryTest.php | 2 - .../Security/User/EntityUserProviderTest.php | 2 +- .../php_deprecation_from_vendor_class.phpt | 2 - .../PhpUnit/Tests/EnumExistsMockTest.php | 3 - .../Tests/Metadata/AttributeReaderTest.php | 5 +- .../Bridge/PhpUnit/bin/simple-phpunit.php | 25 +-- src/Symfony/Bridge/PhpUnit/bootstrap.php | 14 -- .../FrameworkExtension.php | 5 - .../Resources/config/json_streamer.php | 8 - .../Profiler/CodeExtension.php | 22 +- src/Symfony/Component/Clock/Clock.php | 8 +- src/Symfony/Component/Clock/DatePoint.php | 48 +---- src/Symfony/Component/Clock/MockClock.php | 16 +- .../Component/Clock/MonotonicClock.php | 8 +- src/Symfony/Component/Clock/NativeClock.php | 8 +- .../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 +- .../ErrorHandler/DebugClassLoader.php | 2 +- .../Component/ErrorHandler/ErrorHandler.php | 21 -- .../ErrorRenderer/HtmlErrorRenderer.php | 22 +- .../Tests/DebugClassLoaderTest.php | 3 - .../ErrorHandler/Tests/ErrorHandlerTest.php | 8 - .../Component/HttpClient/AmpHttpClient.php | 4 - .../Component/HttpClient/HttpClient.php | 2 +- .../Component/HttpClient/NativeHttpClient.php | 9 +- .../DependencyInjection/ServicesResetter.php | 2 +- .../RequestDataCollectorTest.php | 2 +- .../DependencyInjection/StreamablePass.php | 5 - .../JsonStreamer/JsonStreamReader.php | 8 +- .../JsonStreamer/Read/LazyInstantiator.php | 47 +--- .../StreamablePassTest.php | 3 - .../Tests/JsonStreamReaderTest.php | 32 ++- .../Tests/Read/LazyInstantiatorTest.php | 50 ----- .../Component/Ldap/Security/LdapUser.php | 4 - .../Tests/Hasher/NativePasswordHasherTest.php | 33 --- .../Tests/Hasher/SodiumPasswordHasherTest.php | 33 --- .../Component/Process/Tests/ProcessTest.php | 6 - .../Tests/PropertyAccessorTest.php | 27 +-- .../Extractor/ReflectionExtractor.php | 24 +-- .../Extractor/ReflectionExtractorTest.php | 19 -- .../Core/Authentication/Token/NullToken.php | 3 - .../Core/Tests/User/InMemoryUserTest.php | 2 +- .../Security/Core/User/InMemoryUser.php | 3 - .../Component/Security/Core/User/OidcUser.php | 3 - .../Tests/Normalizer/NumberNormalizerTest.php | 4 - src/Symfony/Component/String/ByteString.php | 33 +-- .../NoSuspiciousCharactersValidator.php | 12 +- .../Component/VarDumper/Caster/Caster.php | 2 +- .../VarDumper/Caster/ReflectionCaster.php | 5 - .../VarDumper/Caster/ResourceCaster.php | 7 +- .../VarDumper/Caster/SocketCaster.php | 20 +- .../VarDumper/Cloner/AbstractCloner.php | 2 - .../VarDumper/Tests/Caster/DOMCasterTest.php | 183 ---------------- .../VarDumper/Tests/Caster/PdoCasterTest.php | 23 +- .../Tests/Caster/ReflectionCasterTest.php | 100 +-------- .../Tests/Caster/ResourceCasterTest.php | 16 -- .../Tests/Caster/SocketCasterTest.php | 62 ------ .../VarDumper/Tests/Caster/StubCasterTest.php | 8 +- .../Tests/Caster/XmlReaderCasterTest.php | 60 ------ .../VarDumper/Tests/Dumper/CliDumperTest.php | 3 - .../VarDumper/Tests/Dumper/HtmlDumperTest.php | 3 - .../VarExporter/Internal/Exporter.php | 4 +- .../VarExporter/Internal/Hydrator.php | 8 +- .../Internal/LazyObjectRegistry.php | 6 +- .../VarExporter/Internal/LazyObjectTrait.php | 27 +-- .../Component/VarExporter/LazyGhostTrait.php | 6 +- .../Component/VarExporter/LazyProxyTrait.php | 6 +- .../Component/VarExporter/ProxyHelper.php | 159 -------------- src/Symfony/Component/VarExporter/README.md | 4 - .../VarExporter/Tests/LazyProxyTraitTest.php | 30 +-- .../Tests/LegacyLazyGhostTraitTest.php | 12 -- .../Tests/LegacyLazyProxyTraitTest.php | 58 ----- .../Tests/LegacyProxyHelperTest.php | 200 ------------------ .../VarExporter/Tests/ProxyHelperTest.php | 6 - .../VarExporter/Tests/VarExporterTest.php | 4 - 91 files changed, 141 insertions(+), 2759 deletions(-) delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_dedup_lazy.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy.php delete mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php delete mode 100644 src/Symfony/Component/VarExporter/Tests/LegacyLazyProxyTraitTest.php delete mode 100644 src/Symfony/Component/VarExporter/Tests/LegacyProxyHelperTest.php diff --git a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php index fa4d88b99455d..5fac3f0a8c3f6 100644 --- a/src/Symfony/Bridge/Doctrine/ManagerRegistry.php +++ b/src/Symfony/Bridge/Doctrine/ManagerRegistry.php @@ -12,8 +12,6 @@ namespace Symfony\Bridge\Doctrine; use Doctrine\Persistence\AbstractManagerRegistry; -use ProxyManager\Proxy\GhostObjectInterface; -use ProxyManager\Proxy\LazyLoadingInterface; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\VarExporter\LazyObjectInterface; @@ -45,34 +43,6 @@ protected function resetService($name): void return; } - if (\PHP_VERSION_ID < 80400) { - if (!$manager instanceof LazyLoadingInterface) { - throw new \LogicException(\sprintf('Resetting a non-lazy manager service is not supported. Declare the "%s" service as lazy.', $name)); - } - trigger_deprecation('symfony/doctrine-bridge', '7.3', 'Support for proxy-manager is deprecated.'); - - 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) { - $name = $this->aliases[$name] ?? $name; - $wrappedInstance = match (true) { - isset($this->fileMap[$name]) => $this->load($this->fileMap[$name], false), - !$method = $this->methodMap[$name] ?? null => throw new \LogicException(\sprintf('The "%s" service is synthetic and cannot be reset.', $name)), - (new \ReflectionMethod($this, $method))->isStatic() => $this->{$method}($this, false), - default => $this->{$method}(false), - }; - $manager->setProxyInitializer(null); - - return true; - }, - $this->container, - Container::class - )); - - return; - } $r = new \ReflectionClass($manager); diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 78b962dfdbcae..48c535726e70d 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -100,7 +100,7 @@ public function refreshUser(UserInterface $user): UserInterface if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) { $refreshedUser->__load(); - } elseif (\PHP_VERSION_ID >= 80400 && ($r = new \ReflectionClass($refreshedUser))->isUninitializedLazyObject($refreshedUser)) { + } elseif (($r = new \ReflectionClass($refreshedUser))->isUninitializedLazyObject($refreshedUser)) { $r->initializeLazyObject($refreshedUser); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php b/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php index 40472ff73ef40..ce1a4aba065ac 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php +++ b/src/Symfony/Bridge/Doctrine/Tests/DoctrineTestHelper.php @@ -47,7 +47,7 @@ public static function createTestEntityManager(?Configuration $config = null): E $config ??= self::createTestConfiguration(); $eventManager = new EventManager(); - if (\PHP_VERSION_ID >= 80400 && method_exists($config, 'enableNativeLazyObjects')) { + if (method_exists($config, 'enableNativeLazyObjects')) { $config->enableNativeLazyObjects(true); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php index 4803e6acaf0af..d2d670eb4e694 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php @@ -50,8 +50,6 @@ public function testResetService() } /** - * @requires PHP 8.4 - * * @dataProvider provideResetServiceWithNativeLazyObjectsCases */ public function testResetServiceWithNativeLazyObjects(string $class) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php index 82bc79f072ecd..ac7f87a3b8e3c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php @@ -220,7 +220,7 @@ public function testRefreshedUserProxyIsLoaded() $provider = new EntityUserProvider($this->getManager($em), User::class); $refreshedUser = $provider->refreshUser($user); - if (\PHP_VERSION_ID >= 80400 && method_exists(Configuration::class, 'enableNativeLazyObjects')) { + if (method_exists(Configuration::class, 'enableNativeLazyObjects')) { $this->assertFalse((new \ReflectionClass(User::class))->isUninitializedLazyObject($refreshedUser)); $this->assertSame('user1', $refreshedUser->name); } else { diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt index 1ead2ef4a4013..3048efbfab53a 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/php_deprecation_from_vendor_class.phpt @@ -1,7 +1,5 @@ --TEST-- Test that a PHP deprecation from a vendor class autoload is considered indirect. ---SKIPIF-- - --FILE-- = 80000) { - $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6'; -} else { - $PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '8.5') ?: '8.5'; -} +$PHPUNIT_VERSION = $getEnvVar('SYMFONY_PHPUNIT_VERSION', '9.6') ?: '9.6'; $MAX_PHPUNIT_VERSION = $getEnvVar('SYMFONY_MAX_PHPUNIT_VERSION', false); @@ -178,7 +174,7 @@ $prevCacheDir = false; } } -$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'.($PHPUNIT_VERSION < 6.0 ? ' symfony/yaml' : '')); +$SYMFONY_PHPUNIT_REMOVE = $getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy'); $SYMFONY_PHPUNIT_REQUIRE = $getEnvVar('SYMFONY_PHPUNIT_REQUIRE', ''); $configurationHash = md5(implode(\PHP_EOL, [md5_file(__FILE__), $SYMFONY_PHPUNIT_REMOVE, $SYMFONY_PHPUNIT_REQUIRE, (int) $PHPUNIT_REMOVE_RETURN_TYPEHINT])); $PHPUNIT_VERSION_DIR = sprintf('phpunit-%s-%d', $PHPUNIT_VERSION, $PHPUNIT_REMOVE_RETURN_TYPEHINT); @@ -240,9 +236,6 @@ if ($SYMFONY_PHPUNIT_REQUIRE) { $passthruOrFail("$COMPOSER require --no-update ".$SYMFONY_PHPUNIT_REQUIRE); } - if (5.1 <= $PHPUNIT_VERSION && $PHPUNIT_VERSION < 5.4) { - $passthruOrFail("$COMPOSER require --no-update phpunit/phpunit-mock-objects \"~3.1.0\""); - } if (preg_match('{\^((\d++\.)\d++)[\d\.]*$}', $info['requires']['php'], $phpVersion) && version_compare($phpVersion[2].'99', \PHP_VERSION, '<')) { $passthruOrFail("$COMPOSER config platform.php \"$phpVersion[1].99\""); @@ -267,9 +260,8 @@ } $prevRoot = getenv('COMPOSER_ROOT_VERSION'); putenv("COMPOSER_ROOT_VERSION=$PHPUNIT_VERSION.99"); - $q = '\\' === \DIRECTORY_SEPARATOR && \PHP_VERSION_ID < 80000 ? '"' : ''; // --no-suggest is not in the list to keep compat with composer 1.0, which is shipped with Ubuntu 16.04LTS - $exit = proc_close(proc_open("$q$COMPOSER update --no-dev --prefer-dist --no-progress $q", [], $p, getcwd())); + $exit = proc_close(proc_open("$COMPOSER update --no-dev --prefer-dist --no-progress", [], $p, getcwd())); putenv('COMPOSER_ROOT_VERSION'.(false !== $prevRoot ? '='.$prevRoot : '')); if ($prevCacheDir) { putenv("COMPOSER_CACHE_DIR=$prevCacheDir"); @@ -340,16 +332,7 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla } chdir($oldPwd); -if ($PHPUNIT_VERSION < 8.0) { - $argv = array_filter($argv, function ($v) use (&$argc) { - if ('--do-not-cache-result' !== $v) { - return true; - } - --$argc; - - return false; - }); -} elseif (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) { +if (filter_var(getenv('SYMFONY_PHPUNIT_DISABLE_RESULT_CACHE'), \FILTER_VALIDATE_BOOLEAN)) { $argv[] = '--do-not-cache-result'; ++$argc; } diff --git a/src/Symfony/Bridge/PhpUnit/bootstrap.php b/src/Symfony/Bridge/PhpUnit/bootstrap.php index 24d593406c87a..5540904749aa9 100644 --- a/src/Symfony/Bridge/PhpUnit/bootstrap.php +++ b/src/Symfony/Bridge/PhpUnit/bootstrap.php @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Deprecations\Deprecation; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler; @@ -35,19 +34,6 @@ if (class_exists(Deprecation::class)) { Deprecation::withoutDeduplication(); - - if (\PHP_VERSION_ID < 80000) { - // Ignore deprecations about the annotation mapping driver when it's not possible to move to the attribute driver yet - Deprecation::ignoreDeprecations('https://github.com/doctrine/orm/issues/10098'); - } -} - -if (!class_exists(AnnotationRegistry::class, false) && class_exists(AnnotationRegistry::class)) { - if (method_exists(AnnotationRegistry::class, 'registerUniqueLoader')) { - AnnotationRegistry::registerUniqueLoader('class_exists'); - } elseif (method_exists(AnnotationRegistry::class, 'registerLoader')) { - AnnotationRegistry::registerLoader('class_exists'); - } } if ( diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 937ba2d2c89ec..7674c97387a6d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -2131,11 +2131,6 @@ private function registerJsonStreamerConfiguration(array $config, ContainerBuild $container->setParameter('.json_streamer.stream_writers_dir', '%kernel.cache_dir%/json_streamer/stream_writer'); $container->setParameter('.json_streamer.stream_readers_dir', '%kernel.cache_dir%/json_streamer/stream_reader'); - $container->setParameter('.json_streamer.lazy_ghosts_dir', '%kernel.cache_dir%/json_streamer/lazy_ghost'); - - if (\PHP_VERSION_ID >= 80400) { - $container->removeDefinition('.json_streamer.cache_warmer.lazy_ghost'); - } } private function registerPropertyInfoConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader): void diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/json_streamer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/json_streamer.php index 79fb25833e066..4b38f0a506176 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/json_streamer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/json_streamer.php @@ -38,7 +38,6 @@ tagged_locator('json_streamer.value_transformer'), service('json_streamer.read.property_metadata_loader'), param('.json_streamer.stream_readers_dir'), - param('.json_streamer.lazy_ghosts_dir'), ]) ->alias(JsonStreamWriter::class, 'json_streamer.stream_writer') ->alias(JsonStreamReader::class, 'json_streamer.stream_reader') @@ -108,12 +107,5 @@ service('logger')->ignoreOnInvalid(), ]) ->tag('kernel.cache_warmer') - - ->set('.json_streamer.cache_warmer.lazy_ghost', LazyGhostCacheWarmer::class) - ->args([ - abstract_arg('streamable class names'), - param('.json_streamer.lazy_ghosts_dir'), - ]) - ->tag('kernel.cache_warmer') ; }; diff --git a/src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php b/src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php index 332a5d6c3725e..3ca805dfa1e80 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Profiler/CodeExtension.php @@ -123,21 +123,13 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri // highlight_file could throw warnings // see https://bugs.php.net/25725 $code = @highlight_file($file, true); - if (\PHP_VERSION_ID >= 80300) { - // remove main pre/code tags - $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); - // split multiline span tags - $code = preg_replace_callback('#]++)>((?:[^<\\n]*+\\n)++[^<]*+)#', function ($m) { - return "".str_replace("\n", "\n", $m[2]).''; - }, $code); - $content = explode("\n", $code); - } else { - // remove main code/span tags - $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); - // split multiline spans - $code = preg_replace_callback('#]++)>((?:[^<]*+
)++[^<]*+)
#', fn ($m) => "".str_replace('
', "

", $m[2]).'', $code); - $content = explode('
', $code); - } + // remove main pre/code tags + $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); + // split multiline span tags + $code = preg_replace_callback('#]++)>((?:[^<\\n]*+\\n)++[^<]*+)#', function ($m) { + return "".str_replace("\n", "\n", $m[2]).''; + }, $code); + $content = explode("\n", $code); $lines = []; if (0 > $srcContext) { diff --git a/src/Symfony/Component/Clock/Clock.php b/src/Symfony/Component/Clock/Clock.php index 311e8fc07abd0..c00a43921de3e 100644 --- a/src/Symfony/Component/Clock/Clock.php +++ b/src/Symfony/Component/Clock/Clock.php @@ -71,14 +71,8 @@ public function sleep(float|int $seconds): void */ public function withTimeZone(\DateTimeZone|string $timezone): static { - if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) { + if (\is_string($timezone)) { $timezone = new \DateTimeZone($timezone); - } elseif (\is_string($timezone)) { - try { - $timezone = new \DateTimeZone($timezone); - } catch (\Exception $e) { - throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e); - } } $clone = clone $this; diff --git a/src/Symfony/Component/Clock/DatePoint.php b/src/Symfony/Component/Clock/DatePoint.php index 4df35fe037256..7b92b76fe6d5c 100644 --- a/src/Symfony/Component/Clock/DatePoint.php +++ b/src/Symfony/Component/Clock/DatePoint.php @@ -30,17 +30,8 @@ public function __construct(string $datetime = 'now', ?\DateTimeZone $timezone = $now = static::createFromInterface($now); } - if (\PHP_VERSION_ID < 80300) { - try { - $builtInDate = new parent($datetime, $timezone ?? $now->getTimezone()); - $timezone = $builtInDate->getTimezone(); - } catch (\Exception $e) { - throw new \DateMalformedStringException($e->getMessage(), $e->getCode(), $e); - } - } else { - $builtInDate = new parent($datetime, $timezone ?? $now->getTimezone()); - $timezone = $builtInDate->getTimezone(); - } + $builtInDate = new parent($datetime, $timezone ?? $now->getTimezone()); + $timezone = $builtInDate->getTimezone(); $now = $now->setTimezone($timezone)->modify($datetime); @@ -74,23 +65,7 @@ public static function createFromMutable(\DateTime $object): static public static function createFromTimestamp(int|float $timestamp): static { - if (\PHP_VERSION_ID >= 80400) { - return parent::createFromTimestamp($timestamp); - } - - if (\is_int($timestamp) || !$ms = (int) $timestamp - $timestamp) { - return static::createFromFormat('U', (string) $timestamp); - } - - if (!is_finite($timestamp) || \PHP_INT_MAX + 1.0 <= $timestamp || \PHP_INT_MIN > $timestamp) { - throw new \DateRangeError(\sprintf('DateTimeImmutable::createFromTimestamp(): Argument #1 ($timestamp) must be a finite number between %s and %s.999999, %s given', \PHP_INT_MIN, \PHP_INT_MAX, $timestamp)); - } - - if ($timestamp < 0) { - $timestamp = (int) $timestamp - 2.0 + $ms; - } - - return static::createFromFormat('U.u', \sprintf('%.6F', $timestamp)); + return parent::createFromTimestamp($timestamp); } public function add(\DateInterval $interval): static @@ -108,10 +83,6 @@ public function sub(\DateInterval $interval): static */ public function modify(string $modifier): static { - if (\PHP_VERSION_ID < 80300) { - return @parent::modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? \sprintf('Invalid modifier: "%s".', $modifier)); - } - return parent::modify($modifier); } @@ -151,19 +122,6 @@ public function setMicrosecond(int $microsecond): static throw new \DateRangeError('DatePoint::setMicrosecond(): Argument #1 ($microsecond) must be between 0 and 999999, '.$microsecond.' given'); } - if (\PHP_VERSION_ID < 80400) { - return $this->setTime(...explode('.', $this->format('H.i.s.'.$microsecond))); - } - return parent::setMicrosecond($microsecond); } - - public function getMicrosecond(): int - { - if (\PHP_VERSION_ID >= 80400) { - return parent::getMicrosecond(); - } - - return $this->format('u'); - } } diff --git a/src/Symfony/Component/Clock/MockClock.php b/src/Symfony/Component/Clock/MockClock.php index 9ba2726bf3453..71500375638af 100644 --- a/src/Symfony/Component/Clock/MockClock.php +++ b/src/Symfony/Component/Clock/MockClock.php @@ -28,14 +28,8 @@ final class MockClock implements ClockInterface */ public function __construct(\DateTimeImmutable|string $now = 'now', \DateTimeZone|string|null $timezone = null) { - if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) { + if (\is_string($timezone)) { $timezone = new \DateTimeZone($timezone); - } elseif (\is_string($timezone)) { - try { - $timezone = new \DateTimeZone($timezone); - } catch (\Exception $e) { - throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e); - } } if (\is_string($now)) { @@ -66,12 +60,6 @@ public function sleep(float|int $seconds): void */ public function modify(string $modifier): void { - if (\PHP_VERSION_ID < 80300) { - $this->now = @$this->now->modify($modifier) ?: throw new \DateMalformedStringException(error_get_last()['message'] ?? \sprintf('Invalid modifier: "%s". Could not modify MockClock.', $modifier)); - - return; - } - $this->now = $this->now->modify($modifier); } @@ -80,7 +68,7 @@ public function modify(string $modifier): void */ public function withTimeZone(\DateTimeZone|string $timezone): static { - if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) { + if (\is_string($timezone)) { $timezone = new \DateTimeZone($timezone); } elseif (\is_string($timezone)) { try { diff --git a/src/Symfony/Component/Clock/MonotonicClock.php b/src/Symfony/Component/Clock/MonotonicClock.php index d27bf9c3134e0..15dc009ea63b2 100644 --- a/src/Symfony/Component/Clock/MonotonicClock.php +++ b/src/Symfony/Component/Clock/MonotonicClock.php @@ -75,14 +75,8 @@ public function sleep(float|int $seconds): void */ public function withTimeZone(\DateTimeZone|string $timezone): static { - if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) { + if (\is_string($timezone)) { $timezone = new \DateTimeZone($timezone); - } elseif (\is_string($timezone)) { - try { - $timezone = new \DateTimeZone($timezone); - } catch (\Exception $e) { - throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e); - } } $clone = clone $this; diff --git a/src/Symfony/Component/Clock/NativeClock.php b/src/Symfony/Component/Clock/NativeClock.php index b580a886cf566..208fd3574c4bd 100644 --- a/src/Symfony/Component/Clock/NativeClock.php +++ b/src/Symfony/Component/Clock/NativeClock.php @@ -49,14 +49,8 @@ public function sleep(float|int $seconds): void */ public function withTimeZone(\DateTimeZone|string $timezone): static { - if (\PHP_VERSION_ID >= 80300 && \is_string($timezone)) { + if (\is_string($timezone)) { $timezone = new \DateTimeZone($timezone); - } elseif (\is_string($timezone)) { - try { - $timezone = new \DateTimeZone($timezone); - } catch (\Exception $e) { - throw new \DateInvalidTimeZoneException($e->getMessage(), $e->getCode(), $e); - } } $clone = clone $this; diff --git a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/LazyServiceInstantiator.php b/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/LazyServiceInstantiator.php index 10748256261e0..77b3def32f818 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/Instantiator/LazyServiceInstantiator.php +++ b/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php b/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php index 0933c1a5993f6..2aefe78b0dcb5 100644 --- a/src/Symfony/Component/DependencyInjection/LazyProxy/PhpDumper/LazyServiceDumper.php +++ b/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php b/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php index 774b1f88b66e7..8360cc3679772 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/ContainerBuilderTest.php +++ b/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php index a117a69a02cf8..9b41b2776d785 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute.php deleted file mode 100644 index 6cf1c86a52ade..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_lazy_autowire_attribute_with_intersection.php deleted file mode 100644 index fcf66ad12157b..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services9_lazy_inlined_factories.txt deleted file mode 100644 index f945fdd50069b..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_dedup_lazy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_dedup_lazy.php deleted file mode 100644 index 60add492ba1cd..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy.php deleted file mode 100644 index f584bef6b97cc..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_as_files.txt deleted file mode 100644 index d52dd5a7b82ac..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_ghost.php deleted file mode 100644 index b03463295309e..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_non_shared_lazy_public.php deleted file mode 100644 index 0841cf192ef59..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy.php deleted file mode 100644 index b9e9164573672..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/legacy_services_wither_lazy_non_shared.php deleted file mode 100644 index d70588f655329..0000000000000 --- a/src/Symfony/Component/DependencyInjection/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/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php index 14d2f81b673ec..a0614c8c73a7f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/LazyProxy/PhpDumper/LazyServiceDumperTest.php +++ b/src/Symfony/Component/DependencyInjection/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)); } } diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index fa9029688873d..69930238195fe 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -868,7 +868,7 @@ private function setReturnType(string $types, string $class, string $method, str $constant = new \ReflectionClassConstant($definingClass, $constantName); - if (\PHP_VERSION_ID >= 80300 && $constantType = $constant->getType()) { + if ($constantType = $constant->getType()) { if ($constantType instanceof \ReflectionNamedType) { $n = $constantType->getName(); } else { diff --git a/src/Symfony/Component/ErrorHandler/ErrorHandler.php b/src/Symfony/Component/ErrorHandler/ErrorHandler.php index 5ffe75e5ef27a..b42075c88957b 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorHandler.php +++ b/src/Symfony/Component/ErrorHandler/ErrorHandler.php @@ -180,11 +180,6 @@ public function __construct( ?BufferingLogger $bootstrappingLogger = null, private bool $debug = false, ) { - if (\PHP_VERSION_ID < 80400) { - $this->levels[\E_STRICT] = 'Runtime Notice'; - $this->loggers[\E_STRICT] = [null, LogLevel::ERROR]; - } - if ($bootstrappingLogger) { $this->bootstrappingLogger = $bootstrappingLogger; $this->setDefaultLogger($bootstrappingLogger); @@ -435,22 +430,6 @@ public function handleError(int $type, string $message, string $file, int $line) return true; } } else { - if (\PHP_VERSION_ID < 80303 && str_contains($message, '@anonymous')) { - $backtrace = debug_backtrace(false, 5); - - for ($i = 1; isset($backtrace[$i]); ++$i) { - if (isset($backtrace[$i]['function'], $backtrace[$i]['args'][0]) - && ('trigger_error' === $backtrace[$i]['function'] || 'user_error' === $backtrace[$i]['function']) - ) { - if ($backtrace[$i]['args'][0] !== $message) { - $message = $backtrace[$i]['args'][0]; - } - - break; - } - } - } - if (str_contains($message, "@anonymous\0")) { $message = $this->parseAnonymousClass($message); $logMessage = $this->levels[$type].': '.$message; diff --git a/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php b/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php index 7bd9a083e53a4..0d07a12a3ea9a 100644 --- a/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php +++ b/src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php @@ -255,21 +255,13 @@ private function fileExcerpt(string $file, int $line, int $srcContext = 3): stri // highlight_file could throw warnings // see https://bugs.php.net/25725 $code = @highlight_file($file, true); - if (\PHP_VERSION_ID >= 80300) { - // remove main pre/code tags - $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); - // split multiline span tags - $code = preg_replace_callback('#]++)>((?:[^<\\n]*+\\n)++[^<]*+)#', function ($m) { - return "".str_replace("\n", "\n", $m[2]).''; - }, $code); - $content = explode("\n", $code); - } else { - // remove main code/span tags - $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); - // split multiline spans - $code = preg_replace_callback('#]++)>((?:[^<]*+
)++[^<]*+)
#', fn ($m) => "".str_replace('
', "

", $m[2]).'', $code); - $content = explode('
', $code); - } + // remove main pre/code tags + $code = preg_replace('#^\s*(.*)\s*#s', '\\1', $code); + // split multiline span tags + $code = preg_replace_callback('#]++)>((?:[^<\\n]*+\\n)++[^<]*+)#', function ($m) { + return "".str_replace("\n", "\n", $m[2]).''; + }, $code); + $content = explode("\n", $code); $lines = []; if (0 > $srcContext) { diff --git a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php index 8575f892dbbe7..0ee60315d27a5 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php @@ -405,9 +405,6 @@ class_exists('Test\\'.ReturnType::class, true); ], $deprecations); } - /** - * @requires PHP >= 8.3 - */ public function testReturnTypePhp83() { $deprecations = []; diff --git a/src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php b/src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php index 5f55cfb2c969d..350a8e865aa97 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/ErrorHandlerTest.php @@ -214,10 +214,6 @@ public function testDefaultLogger() \E_CORE_ERROR => [null, LogLevel::CRITICAL], ]; - if (\PHP_VERSION_ID < 80400) { - $loggers[\E_STRICT] = [null, LogLevel::ERROR]; - } - $this->assertSame($loggers, $handler->setLoggers([])); } finally { restore_error_handler(); @@ -455,10 +451,6 @@ public function testBootstrappingLogger() \E_CORE_ERROR => [$bootLogger, LogLevel::CRITICAL], ]; - if (\PHP_VERSION_ID < 80400) { - $loggers[\E_STRICT] = [$bootLogger, LogLevel::ERROR]; - } - $this->assertSame($loggers, $handler->setLoggers([])); $handler->handleError(\E_DEPRECATED, 'Foo message', __FILE__, 123, []); diff --git a/src/Symfony/Component/HttpClient/AmpHttpClient.php b/src/Symfony/Component/HttpClient/AmpHttpClient.php index 4c73fbaf3db24..6bb41af6058d5 100644 --- a/src/Symfony/Component/HttpClient/AmpHttpClient.php +++ b/src/Symfony/Component/HttpClient/AmpHttpClient.php @@ -36,10 +36,6 @@ throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client:^4.2.1".'); } -if (\PHP_VERSION_ID < 80400 && is_subclass_of(Request::class, HttpMessage::class)) { - throw new \LogicException('Using "Symfony\Component\HttpClient\AmpHttpClient" with amphp/http-client >= 5 requires PHP >= 8.4. Try running "composer require amphp/http-client:^4.2.1" or upgrade to PHP >= 8.4.'); -} - /** * A portable implementation of the HttpClientInterface contracts based on Amp's HTTP client. * diff --git a/src/Symfony/Component/HttpClient/HttpClient.php b/src/Symfony/Component/HttpClient/HttpClient.php index 3eb3665614fd7..7bd70688643dd 100644 --- a/src/Symfony/Component/HttpClient/HttpClient.php +++ b/src/Symfony/Component/HttpClient/HttpClient.php @@ -31,7 +31,7 @@ final class HttpClient */ public static function create(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50): HttpClientInterface { - if ($amp = class_exists(AmpRequest::class) && (\PHP_VERSION_ID >= 80400 || !is_subclass_of(AmpRequest::class, HttpMessage::class))) { + if ($amp = class_exists(AmpRequest::class)) { if (!\extension_loaded('curl')) { return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes); } diff --git a/src/Symfony/Component/HttpClient/NativeHttpClient.php b/src/Symfony/Component/HttpClient/NativeHttpClient.php index 941d37542c3ad..0022d584a6cb5 100644 --- a/src/Symfony/Component/HttpClient/NativeHttpClient.php +++ b/src/Symfony/Component/HttpClient/NativeHttpClient.php @@ -80,9 +80,6 @@ public function request(string $method, string $url, array $options = []): Respo if (str_starts_with($options['bindto'], 'host!')) { $options['bindto'] = substr($options['bindto'], 5); } - if ((\PHP_VERSION_ID < 80223 || 80300 <= \PHP_VERSION_ID && 80311 < \PHP_VERSION_ID) && '\\' === \DIRECTORY_SEPARATOR && '[' === $options['bindto'][0]) { - $options['bindto'] = preg_replace('{^\[[^\]]++\]}', '[$0]', $options['bindto']); - } } $hasContentLength = isset($options['normalized_headers']['content-length']); @@ -429,11 +426,7 @@ private static function createRedirectResolver(array $options, string $authority $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders); $redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders); - if (\PHP_VERSION_ID >= 80300) { - stream_context_set_options($context, ['http' => $options]); - } else { - stream_context_set_option($context, ['http' => $options]); - } + stream_context_set_options($context, ['http' => $options]); } } diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/ServicesResetter.php b/src/Symfony/Component/HttpKernel/DependencyInjection/ServicesResetter.php index 57e394fcc5d69..2f7c35ee67754 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/ServicesResetter.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/ServicesResetter.php @@ -45,7 +45,7 @@ public function reset(): void continue; } - if (\PHP_VERSION_ID >= 80400 && (new \ReflectionClass($service))->isUninitializedLazyObject($service)) { + if (new \ReflectionClass($service)->isUninitializedLazyObject($service)) { continue; } diff --git a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php index 93ba4c1fc3e38..2c4c972355f04 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php @@ -117,7 +117,7 @@ public static function provideControllerCallables(): array 'Closure', fn () => 'foo', [ - 'class' => \PHP_VERSION_ID >= 80400 ? \sprintf('{closure:%s():%d}', __METHOD__, __LINE__ - 2) : __NAMESPACE__.'\{closure}', + 'class' => \sprintf('{closure:%s():%d}', __METHOD__, __LINE__ - 2), 'method' => null, 'file' => __FILE__, 'line' => __LINE__ - 5, diff --git a/src/Symfony/Component/JsonStreamer/DependencyInjection/StreamablePass.php b/src/Symfony/Component/JsonStreamer/DependencyInjection/StreamablePass.php index babf962bfcdaa..590b667770485 100644 --- a/src/Symfony/Component/JsonStreamer/DependencyInjection/StreamablePass.php +++ b/src/Symfony/Component/JsonStreamer/DependencyInjection/StreamablePass.php @@ -47,10 +47,5 @@ public function process(ContainerBuilder $container): void $container->getDefinition('.json_streamer.cache_warmer.streamer') ->replaceArgument(0, $streamable); - - if ($container->hasDefinition('.json_streamer.cache_warmer.lazy_ghost')) { - $container->getDefinition('.json_streamer.cache_warmer.lazy_ghost') - ->replaceArgument(0, array_keys($streamable)); - } } } diff --git a/src/Symfony/Component/JsonStreamer/JsonStreamReader.php b/src/Symfony/Component/JsonStreamer/JsonStreamReader.php index e813f4a8a5408..c66ccf08ac6d3 100644 --- a/src/Symfony/Component/JsonStreamer/JsonStreamReader.php +++ b/src/Symfony/Component/JsonStreamer/JsonStreamReader.php @@ -45,11 +45,10 @@ public function __construct( private ContainerInterface $valueTransformers, PropertyMetadataLoaderInterface $propertyMetadataLoader, string $streamReadersDir, - ?string $lazyGhostsDir = null, ) { $this->streamReaderGenerator = new StreamReaderGenerator($propertyMetadataLoader, $streamReadersDir); $this->instantiator = new Instantiator(); - $this->lazyInstantiator = new LazyInstantiator($lazyGhostsDir); + $this->lazyInstantiator = new LazyInstantiator(); } public function read($input, Type $type, array $options = []): mixed @@ -63,10 +62,9 @@ public function read($input, Type $type, array $options = []): mixed /** * @param array $valueTransformers */ - public static function create(array $valueTransformers = [], ?string $streamReadersDir = null, ?string $lazyGhostsDir = null): self + public static function create(array $valueTransformers = [], ?string $streamReadersDir = null): self { $streamReadersDir ??= sys_get_temp_dir().'/json_streamer/read'; - $lazyGhostsDir ??= sys_get_temp_dir().'/json_streamer/lazy_ghost'; $valueTransformers += [ 'json_streamer.value_transformer.string_to_date_time' => new StringToDateTimeValueTransformer(), ]; @@ -101,6 +99,6 @@ public function get(string $id): ValueTransformerInterface $typeContextFactory, ); - return new self($valueTransformersContainer, $propertyMetadataLoader, $streamReadersDir, $lazyGhostsDir); + return new self($valueTransformersContainer, $propertyMetadataLoader, $streamReadersDir); } } diff --git a/src/Symfony/Component/JsonStreamer/Read/LazyInstantiator.php b/src/Symfony/Component/JsonStreamer/Read/LazyInstantiator.php index a9bd55553ad9d..6b0ddb3742923 100644 --- a/src/Symfony/Component/JsonStreamer/Read/LazyInstantiator.php +++ b/src/Symfony/Component/JsonStreamer/Read/LazyInstantiator.php @@ -11,15 +11,11 @@ namespace Symfony\Component\JsonStreamer\Read; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\JsonStreamer\Exception\InvalidArgumentException; use Symfony\Component\JsonStreamer\Exception\RuntimeException; -use Symfony\Component\VarExporter\ProxyHelper; /** - * Instantiates a new $className lazy ghost {@see \Symfony\Component\VarExporter\LazyGhostTrait}. + * Instantiates a new $className lazy ghost. * - * Prior to PHP 8.4, the "$className" argument class must not be final. * The $initializer must be a callable that sets the actual object values when being called. * * @author Mathias Arlaud @@ -28,8 +24,6 @@ */ final class LazyInstantiator { - private ?Filesystem $fs = null; - /** * @var array{reflection: array>, lazy_class_name: array} */ @@ -38,19 +32,6 @@ final class LazyInstantiator 'lazy_class_name' => [], ]; - /** - * @var array - */ - private static array $lazyClassesLoaded = []; - - public function __construct( - private ?string $lazyGhostsDir = null, - ) { - if (null === $this->lazyGhostsDir && \PHP_VERSION_ID < 80400) { - throw new InvalidArgumentException('The "$lazyGhostsDir" argument cannot be null when using PHP < 8.4.'); - } - } - /** * @template T of object * @@ -68,30 +49,6 @@ public function instantiate(string $className, callable $initializer): object } // use native lazy ghosts if available - if (\PHP_VERSION_ID >= 80400) { - return $classReflection->newLazyGhost($initializer); - } - - $this->fs ??= new Filesystem(); - - $lazyClassName = self::$cache['lazy_class_name'][$className] ??= \sprintf('%sGhost', preg_replace('/\\\\/', '', $className)); - - if (isset(self::$lazyClassesLoaded[$className]) && class_exists($lazyClassName)) { - return $lazyClassName::createLazyGhost($initializer); - } - - if (!is_file($path = \sprintf('%s%s%s.php', $this->lazyGhostsDir, \DIRECTORY_SEPARATOR, hash('xxh128', $className)))) { - if (!$this->fs->exists($this->lazyGhostsDir)) { - $this->fs->mkdir($this->lazyGhostsDir); - } - - $this->fs->dumpFile($path, \sprintf('newLazyGhost($initializer); } } diff --git a/src/Symfony/Component/JsonStreamer/Tests/DependencyInjection/StreamablePassTest.php b/src/Symfony/Component/JsonStreamer/Tests/DependencyInjection/StreamablePassTest.php index f58bc9ce81998..2e935a57514e6 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/DependencyInjection/StreamablePassTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/DependencyInjection/StreamablePassTest.php @@ -23,7 +23,6 @@ public function testSetStreamable() $container->register('json_streamer.stream_writer'); $container->register('.json_streamer.cache_warmer.streamer')->setArguments([null]); - $container->register('.json_streamer.cache_warmer.lazy_ghost')->setArguments([null]); $container->register('streamable')->setClass('Foo')->addTag('json_streamer.streamable', ['object' => true, 'list' => true]); $container->register('abstractStreamable')->setClass('Bar')->addTag('json_streamer.streamable', ['object' => true, 'list' => true])->setAbstract(true); @@ -33,9 +32,7 @@ public function testSetStreamable() $pass->process($container); $streamerCacheWarmer = $container->getDefinition('.json_streamer.cache_warmer.streamer'); - $lazyGhostCacheWarmer = $container->getDefinition('.json_streamer.cache_warmer.lazy_ghost'); $this->assertSame(['Foo' => ['object' => true, 'list' => true]], $streamerCacheWarmer->getArgument(0)); - $this->assertSame(['Foo'], $lazyGhostCacheWarmer->getArgument(0)); } } diff --git a/src/Symfony/Component/JsonStreamer/Tests/JsonStreamReaderTest.php b/src/Symfony/Component/JsonStreamer/Tests/JsonStreamReaderTest.php index 6538a6d32383c..7b7f63da72deb 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/JsonStreamReaderTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/JsonStreamReaderTest.php @@ -29,29 +29,22 @@ class JsonStreamReaderTest extends TestCase { private string $streamReadersDir; - private string $lazyGhostsDir; protected function setUp(): void { parent::setUp(); $this->streamReadersDir = \sprintf('%s/symfony_json_streamer_test/stream_reader', sys_get_temp_dir()); - $this->lazyGhostsDir = \sprintf('%s/symfony_json_streamer_test/lazy_ghost', sys_get_temp_dir()); if (is_dir($this->streamReadersDir)) { array_map('unlink', glob($this->streamReadersDir.'/*')); rmdir($this->streamReadersDir); } - - if (is_dir($this->lazyGhostsDir)) { - array_map('unlink', glob($this->lazyGhostsDir.'/*')); - rmdir($this->lazyGhostsDir); - } } public function testReadScalar() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, null, 'null', Type::nullable(Type::int())); $this->assertRead($reader, true, 'true', Type::bool()); @@ -63,7 +56,7 @@ public function testReadScalar() public function testReadCollection() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead( $reader, @@ -92,7 +85,7 @@ public function testReadCollection() public function testReadObject() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(ClassicDummy::class, $read); @@ -103,7 +96,7 @@ public function testReadObject() public function testReadObjectWithGenerics() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(DummyWithGenerics::class, $read); @@ -114,7 +107,7 @@ public function testReadObjectWithGenerics() public function testReadObjectWithStreamedName() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(DummyWithNameAttributes::class, $read); @@ -125,12 +118,11 @@ public function testReadObjectWithStreamedName() public function testReadObjectWithValueTransformer() { $reader = JsonStreamReader::create( - valueTransformers: [ + [ StringToBooleanValueTransformer::class => new StringToBooleanValueTransformer(), DivideStringAndCastToIntValueTransformer::class => new DivideStringAndCastToIntValueTransformer(), ], - streamReadersDir: $this->streamReadersDir, - lazyGhostsDir: $this->lazyGhostsDir, + $this->streamReadersDir, ); $this->assertRead($reader, function (mixed $read) { @@ -144,7 +136,7 @@ public function testReadObjectWithValueTransformer() public function testReadObjectWithPhpDoc() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(DummyWithPhpDoc::class, $read); @@ -156,7 +148,7 @@ public function testReadObjectWithPhpDoc() public function testReadObjectWithNullableProperties() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(DummyWithNullableProperties::class, $read); @@ -167,7 +159,7 @@ public function testReadObjectWithNullableProperties() public function testReadObjectWithDateTimes() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $this->assertRead($reader, function (mixed $read) { $this->assertInstanceOf(DummyWithDateTimes::class, $read); @@ -178,7 +170,7 @@ public function testReadObjectWithDateTimes() public function testCreateStreamReaderFile() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); $reader->read('true', Type::bool()); @@ -188,7 +180,7 @@ public function testCreateStreamReaderFile() public function testCreateStreamReaderFileOnlyIfNotExists() { - $reader = JsonStreamReader::create(streamReadersDir: $this->streamReadersDir, lazyGhostsDir: $this->lazyGhostsDir); + $reader = JsonStreamReader::create([], $this->streamReadersDir); if (!file_exists($this->streamReadersDir)) { mkdir($this->streamReadersDir, recursive: true); diff --git a/src/Symfony/Component/JsonStreamer/Tests/Read/LazyInstantiatorTest.php b/src/Symfony/Component/JsonStreamer/Tests/Read/LazyInstantiatorTest.php index 90e5f498d9cd2..eb506cf332d4e 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/Read/LazyInstantiatorTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/Read/LazyInstantiatorTest.php @@ -12,61 +12,11 @@ namespace Symfony\Component\JsonStreamer\Tests\Read; use PHPUnit\Framework\TestCase; -use Symfony\Component\JsonStreamer\Exception\InvalidArgumentException; use Symfony\Component\JsonStreamer\Read\LazyInstantiator; use Symfony\Component\JsonStreamer\Tests\Fixtures\Model\ClassicDummy; class LazyInstantiatorTest extends TestCase { - private string $lazyGhostsDir; - - protected function setUp(): void - { - parent::setUp(); - - $this->lazyGhostsDir = \sprintf('%s/symfony_json_streamer_test/lazy_ghost', sys_get_temp_dir()); - - if (is_dir($this->lazyGhostsDir)) { - array_map('unlink', glob($this->lazyGhostsDir.'/*')); - rmdir($this->lazyGhostsDir); - } - } - - /** - * @requires PHP < 8.4 - */ - public function testCreateLazyGhostUsingVarExporter() - { - $ghost = (new LazyInstantiator($this->lazyGhostsDir))->instantiate(ClassicDummy::class, function (ClassicDummy $object): void { - $object->id = 123; - }); - - $this->assertSame(123, $ghost->id); - } - - /** - * @requires PHP < 8.4 - */ - public function testCreateCacheFile() - { - // use DummyForLazyInstantiation class to be sure that the instantiated object is not already in cache. - (new LazyInstantiator($this->lazyGhostsDir))->instantiate(DummyForLazyInstantiation::class, function (DummyForLazyInstantiation $object): void {}); - - $this->assertCount(1, glob($this->lazyGhostsDir.'/*')); - } - - /** - * @requires PHP < 8.4 - */ - public function testThrowIfLazyGhostDirNotDefined() - { - $this->expectException(InvalidArgumentException::class); - new LazyInstantiator(); - } - - /** - * @requires PHP 8.4 - */ public function testCreateLazyGhostUsingPhp() { $ghost = (new LazyInstantiator())->instantiate(ClassicDummy::class, function (ClassicDummy $object): void { diff --git a/src/Symfony/Component/Ldap/Security/LdapUser.php b/src/Symfony/Component/Ldap/Security/LdapUser.php index 020fcb5441596..c1a2ed30c7af5 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUser.php +++ b/src/Symfony/Component/Ldap/Security/LdapUser.php @@ -66,10 +66,6 @@ public function getUserIdentifier(): string #[\Deprecated(since: 'symfony/ldap 7.3')] public function eraseCredentials(): void { - if (\PHP_VERSION_ID < 80400) { - @trigger_error(\sprintf('Method %s::eraseCredentials() is deprecated since symfony/ldap 7.3', self::class), \E_USER_DEPRECATED); - } - $this->password = null; } diff --git a/src/Symfony/Component/PasswordHasher/Tests/Hasher/NativePasswordHasherTest.php b/src/Symfony/Component/PasswordHasher/Tests/Hasher/NativePasswordHasherTest.php index a21b6d6119b04..7ed4fbd80c638 100644 --- a/src/Symfony/Component/PasswordHasher/Tests/Hasher/NativePasswordHasherTest.php +++ b/src/Symfony/Component/PasswordHasher/Tests/Hasher/NativePasswordHasherTest.php @@ -99,39 +99,6 @@ public function testBcryptWithLongPassword() $this->assertTrue($hasher->verify($hasher->hash($plainPassword), $plainPassword)); } - /** - * @requires PHP < 8.4 - */ - public function testBcryptWithNulByteWithNativePasswordHash() - { - $hasher = new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT); - $plainPassword = "a\0b"; - - try { - $hash = password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]); - } catch (\Throwable $throwable) { - // we skip the test in case the current PHP version does not support NUL bytes in passwords - // with bcrypt - // - // @see https://github.com/php/php-src/commit/11f2568767660ffe92fbc6799800e01203aad73a - if (str_contains($throwable->getMessage(), 'Bcrypt password must not contain null character')) { - $this->markTestSkipped('password_hash() does not accept passwords containing NUL bytes.'); - } - - throw $throwable; - } - - if (null === $hash) { - // we also skip the test in case password_hash() returns null as - // implemented in security patches backports - // - // @see https://github.com/shivammathur/php-src-backports/commit/d22d9ebb29dce86edd622205dd1196a2796c08c7 - $this->markTestSkipped('password_hash() does not accept passwords containing NUL bytes.'); - } - - $this->assertFalse($hasher->verify($hash, $plainPassword)); - } - public function testPasswordNulByteGracefullyHandled() { $hasher = new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT); diff --git a/src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php b/src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php index 0a8b7ea88c0cc..aa52ce952c260 100644 --- a/src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php +++ b/src/Symfony/Component/PasswordHasher/Tests/Hasher/SodiumPasswordHasherTest.php @@ -73,39 +73,6 @@ public function testBcryptWithLongPassword() $this->assertTrue($hasher->verify((new NativePasswordHasher(null, null, 4, \PASSWORD_BCRYPT))->hash($plainPassword), $plainPassword)); } - /** - * @requires PHP < 8.4 - */ - public function testBcryptWithNulByteWithNativePasswordHash() - { - $hasher = new SodiumPasswordHasher(null, null); - $plainPassword = "a\0b"; - - try { - $hash = password_hash($plainPassword, \PASSWORD_BCRYPT, ['cost' => 4]); - } catch (\Throwable $throwable) { - // we skip the test in case the current PHP version does not support NUL bytes in passwords - // with bcrypt - // - // @see https://github.com/php/php-src/commit/11f2568767660ffe92fbc6799800e01203aad73a - if (str_contains($throwable->getMessage(), 'Bcrypt password must not contain null character')) { - $this->markTestSkipped('password_hash() does not accept passwords containing NUL bytes.'); - } - - throw $throwable; - } - - if (null === $hash) { - // we also skip the test in case password_hash() returns null as - // implemented in security patches backports - // - // @see https://github.com/shivammathur/php-src-backports/commit/d22d9ebb29dce86edd622205dd1196a2796c08c7 - $this->markTestSkipped('password_hash() does not accept passwords containing NUL bytes.'); - } - - $this->assertFalse($hasher->verify($hash, $plainPassword)); - } - public function testPasswordNulByteGracefullyHandled() { $hasher = new SodiumPasswordHasher(null, null); diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 17f98a664f4b9..ef63f7a618122 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -746,9 +746,6 @@ public function testProcessIsSignaledIfStopped() if ('\\' === \DIRECTORY_SEPARATOR) { $this->markTestSkipped('Windows does not support POSIX signals'); } - if (\PHP_VERSION_ID < 80300 && isset($_SERVER['GITHUB_ACTIONS'])) { - $this->markTestSkipped('Transient on GHA with PHP < 8.3'); - } $process = $this->getProcessForCode('sleep(32);'); $process->start(); @@ -1700,9 +1697,6 @@ public function testNotIgnoringSignal() if (!\function_exists('pcntl_signal')) { $this->markTestSkipped('pnctl extension is required.'); } - if (\PHP_VERSION_ID < 80300 && isset($_SERVER['GITHUB_ACTIONS'])) { - $this->markTestSkipped('Transient on GHA with PHP < 8.3'); - } $process = $this->getProcess(['sleep', '10']); diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php index bb8043d5d45bd..d75e62766bf04 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php @@ -1032,29 +1032,9 @@ public function testIsReadableWithMissingPropertyAndLazyGhost() private function createUninitializedObjectPropertyGhost(): UninitializedObjectProperty { - if (\PHP_VERSION_ID < 80400) { - if (!class_exists(ProxyHelper::class)) { - $this->markTestSkipped(\sprintf('Class "%s" is required to run this test.', ProxyHelper::class)); - } - - $class = 'UninitializedObjectPropertyGhost'; - - if (!class_exists($class)) { - eval('class '.$class.ProxyHelper::generateLazyGhost(new \ReflectionClass(UninitializedObjectProperty::class))); - } - - $this->assertTrue(class_exists($class)); - - return $class::createLazyGhost(initializer: function ($instance) { - }); - } - - return (new \ReflectionClass(UninitializedObjectProperty::class))->newLazyGhost(fn () => null); + return new \ReflectionClass(UninitializedObjectProperty::class)->newLazyGhost(fn () => null); } - /** - * @requires PHP 8.4 - */ public function testIsWritableWithAsymmetricVisibility() { $object = new AsymmetricVisibility(); @@ -1066,9 +1046,6 @@ public function testIsWritableWithAsymmetricVisibility() $this->assertFalse($this->propertyAccessor->isWritable($object, 'virtualNoSetHook')); } - /** - * @requires PHP 8.4 - */ public function testIsReadableWithAsymmetricVisibility() { $object = new AsymmetricVisibility(); @@ -1081,8 +1058,6 @@ public function testIsReadableWithAsymmetricVisibility() } /** - * @requires PHP 8.4 - * * @dataProvider setValueWithAsymmetricVisibilityDataProvider */ public function testSetValueWithAsymmetricVisibility(string $propertyPath, ?string $expectedException) diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 39b16caeb86e3..78a37e257f470 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -723,15 +723,15 @@ private function isAllowedProperty(string $class, string $property, bool $writeA return false; } - if (\PHP_VERSION_ID >= 80400 && $reflectionProperty->isProtectedSet()) { + if ($reflectionProperty->isProtectedSet()) { return (bool) ($this->propertyReflectionFlags & \ReflectionProperty::IS_PROTECTED); } - if (\PHP_VERSION_ID >= 80400 && $reflectionProperty->isPrivateSet()) { + if ($reflectionProperty->isPrivateSet()) { return (bool) ($this->propertyReflectionFlags & \ReflectionProperty::IS_PRIVATE); } - if (\PHP_VERSION_ID >= 80400 && $reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { + if ($reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { return false; } } @@ -974,18 +974,16 @@ private function getReadVisibilityForMethod(\ReflectionMethod $reflectionMethod) private function getWriteVisibilityForProperty(\ReflectionProperty $reflectionProperty): string { - if (\PHP_VERSION_ID >= 80400) { - if ($reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { - return PropertyWriteInfo::VISIBILITY_PRIVATE; - } + if ($reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) { + return PropertyWriteInfo::VISIBILITY_PRIVATE; + } - if ($reflectionProperty->isPrivateSet()) { - return PropertyWriteInfo::VISIBILITY_PRIVATE; - } + if ($reflectionProperty->isPrivateSet()) { + return PropertyWriteInfo::VISIBILITY_PRIVATE; + } - if ($reflectionProperty->isProtectedSet()) { - return PropertyWriteInfo::VISIBILITY_PROTECTED; - } + if ($reflectionProperty->isProtectedSet()) { + return PropertyWriteInfo::VISIBILITY_PROTECTED; } if ($reflectionProperty->isPrivate()) { diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php index fbf365ea5f2c4..330a35db87746 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php @@ -724,9 +724,6 @@ public static function provideLegacyExtractConstructorTypes(): array ]; } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibility() { $this->assertTrue($this->extractor->isReadable(AsymmetricVisibility::class, 'publicPrivate')); @@ -737,9 +734,6 @@ public function testAsymmetricVisibility() $this->assertFalse($this->extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate')); } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibilityAllowPublicOnly() { $extractor = new ReflectionExtractor(null, null, null, true, ReflectionExtractor::ALLOW_PUBLIC); @@ -752,9 +746,6 @@ public function testAsymmetricVisibilityAllowPublicOnly() $this->assertFalse($extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate')); } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibilityAllowProtectedOnly() { $extractor = new ReflectionExtractor(null, null, null, true, ReflectionExtractor::ALLOW_PROTECTED); @@ -767,9 +758,6 @@ public function testAsymmetricVisibilityAllowProtectedOnly() $this->assertFalse($extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate')); } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibilityAllowPrivateOnly() { $extractor = new ReflectionExtractor(null, null, null, true, ReflectionExtractor::ALLOW_PRIVATE); @@ -782,9 +770,6 @@ public function testAsymmetricVisibilityAllowPrivateOnly() $this->assertTrue($extractor->isWritable(AsymmetricVisibility::class, 'protectedPrivate')); } - /** - * @requires PHP 8.4 - */ public function testVirtualProperties() { $this->assertTrue($this->extractor->isReadable(VirtualProperties::class, 'virtualNoSetHook')); @@ -797,8 +782,6 @@ public function testVirtualProperties() /** * @dataProvider provideAsymmetricVisibilityMutator - * - * @requires PHP 8.4 */ public function testAsymmetricVisibilityMutator(string $property, string $readVisibility, string $writeVisibility) { @@ -823,8 +806,6 @@ public static function provideAsymmetricVisibilityMutator(): iterable /** * @dataProvider provideVirtualPropertiesMutator - * - * @requires PHP 8.4 */ public function testVirtualPropertiesMutator(string $property, string $readVisibility, string $writeVisibility) { diff --git a/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php b/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php index cb2bc0fd24225..9eee0909290f1 100644 --- a/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php +++ b/src/Symfony/Component/Security/Core/Authentication/Token/NullToken.php @@ -49,9 +49,6 @@ public function getUserIdentifier(): string #[\Deprecated(since: 'symfony/security-core 7.3')] public function eraseCredentials(): void { - if (\PHP_VERSION_ID < 80400) { - @trigger_error(\sprintf('Method %s::eraseCredentials() is deprecated since symfony/security-core 7.3', self::class), \E_USER_DEPRECATED); - } } public function getAttributes(): array diff --git a/src/Symfony/Component/Security/Core/Tests/User/InMemoryUserTest.php b/src/Symfony/Component/Security/Core/Tests/User/InMemoryUserTest.php index f06e98c32c80f..7cec7502464d7 100644 --- a/src/Symfony/Component/Security/Core/Tests/User/InMemoryUserTest.php +++ b/src/Symfony/Component/Security/Core/Tests/User/InMemoryUserTest.php @@ -62,7 +62,7 @@ public function testIsEnabled() public function testEraseCredentials() { $user = new InMemoryUser('fabien', 'superpass'); - $this->expectUserDeprecationMessage(\sprintf('%sMethod %s::eraseCredentials() is deprecated since symfony/security-core 7.3', \PHP_VERSION_ID >= 80400 ? 'Unsilenced deprecation: ' : '', InMemoryUser::class)); + $this->expectUserDeprecationMessage(\sprintf('Unsilenced deprecation: Method %s::eraseCredentials() is deprecated since symfony/security-core 7.3', InMemoryUser::class)); $user->eraseCredentials(); $this->assertEquals('superpass', $user->getPassword()); } diff --git a/src/Symfony/Component/Security/Core/User/InMemoryUser.php b/src/Symfony/Component/Security/Core/User/InMemoryUser.php index 7bed183a64d8e..9554350186939 100644 --- a/src/Symfony/Component/Security/Core/User/InMemoryUser.php +++ b/src/Symfony/Component/Security/Core/User/InMemoryUser.php @@ -80,9 +80,6 @@ public function isEnabled(): bool #[\Deprecated(since: 'symfony/security-core 7.3')] public function eraseCredentials(): void { - if (\PHP_VERSION_ID < 80400) { - @trigger_error(\sprintf('Method %s::eraseCredentials() is deprecated since symfony/security-core 7.3', self::class), \E_USER_DEPRECATED); - } } public function isEqualTo(UserInterface $user): bool diff --git a/src/Symfony/Component/Security/Core/User/OidcUser.php b/src/Symfony/Component/Security/Core/User/OidcUser.php index df59c5f7840d6..086928692a3f4 100644 --- a/src/Symfony/Component/Security/Core/User/OidcUser.php +++ b/src/Symfony/Component/Security/Core/User/OidcUser.php @@ -77,9 +77,6 @@ public function getUserIdentifier(): string #[\Deprecated(since: 'symfony/security-core 7.3')] public function eraseCredentials(): void { - if (\PHP_VERSION_ID < 80400) { - @trigger_error(\sprintf('Method %s::eraseCredentials() is deprecated since symfony/security-core 7.3', self::class), \E_USER_DEPRECATED); - } } public function getSub(): ?string diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/NumberNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/NumberNormalizerTest.php index 56d4776b2227d..04e6e5c8b6da9 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/NumberNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/NumberNormalizerTest.php @@ -52,7 +52,6 @@ public static function supportsNormalizationProvider(): iterable } /** - * @requires PHP 8.4 * @requires extension bcmath * * @dataProvider normalizeGoodBcMathNumberValueProvider @@ -108,7 +107,6 @@ public static function normalizeBadValueProvider(): iterable } /** - * @requires PHP 8.4 * @requires extension bcmath */ public function testSupportsBcMathNumberDenormalization() @@ -130,7 +128,6 @@ public function testDoesNotSupportOtherValuesDenormalization() } /** - * @requires PHP 8.4 * @requires extension bcmath * * @dataProvider denormalizeGoodBcMathNumberValueProvider @@ -168,7 +165,6 @@ public static function denormalizeGoodGmpValueProvider(): iterable } /** - * @requires PHP 8.4 * @requires extension bcmath * * @dataProvider denormalizeBadBcMathNumberValueProvider diff --git a/src/Symfony/Component/String/ByteString.php b/src/Symfony/Component/String/ByteString.php index 5cbfd6de44bea..42c87b75951a1 100644 --- a/src/Symfony/Component/String/ByteString.php +++ b/src/Symfony/Component/String/ByteString.php @@ -56,38 +56,7 @@ public static function fromRandom(int $length = 16, ?string $alphabet = null): s throw new InvalidArgumentException('The length of the alphabet must in the [2^1, 2^56] range.'); } - if (\PHP_VERSION_ID >= 80300) { - return new static((new Randomizer())->getBytesFromString($alphabet, $length)); - } - - $ret = ''; - while ($length > 0) { - $urandomLength = (int) ceil(2 * $length * $bits / 8.0); - $data = random_bytes($urandomLength); - $unpackedData = 0; - $unpackedBits = 0; - for ($i = 0; $i < $urandomLength && $length > 0; ++$i) { - // Unpack 8 bits - $unpackedData = ($unpackedData << 8) | \ord($data[$i]); - $unpackedBits += 8; - - // While we have enough bits to select a character from the alphabet, keep - // consuming the random data - for (; $unpackedBits >= $bits && $length > 0; $unpackedBits -= $bits) { - $index = ($unpackedData & ((1 << $bits) - 1)); - $unpackedData >>= $bits; - // Unfortunately, the alphabet size is not necessarily a power of two. - // Worst case, it is 2^k + 1, which means we need (k+1) bits and we - // have around a 50% chance of missing as k gets larger - if ($index < $alphabetSize) { - $ret .= $alphabet[$index]; - --$length; - } - } - } - } - - return new static($ret); + return new static((new Randomizer())->getBytesFromString($alphabet, $length)); } public function bytesAt(int $offset): array diff --git a/src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php b/src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php index 0b7a78ef92e40..d82a62d57dd60 100644 --- a/src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php +++ b/src/Symfony/Component/Validator/Constraints/NoSuspiciousCharactersValidator.php @@ -99,17 +99,7 @@ public function validate(mixed $value, Constraint $constraint): void } foreach (self::CHECK_ERROR as $check => $error) { - if (\PHP_VERSION_ID < 80204) { - if (!($checks & $check)) { - continue; - } - - $checker->setChecks($check); - - if (!$checker->isSuspicious($value)) { - continue; - } - } elseif (!($errorCode & $check)) { + if (!($errorCode & $check)) { continue; } diff --git a/src/Symfony/Component/VarDumper/Caster/Caster.php b/src/Symfony/Component/VarDumper/Caster/Caster.php index c3bc54e3ac00b..ed088cedbc597 100644 --- a/src/Symfony/Component/VarDumper/Caster/Caster.php +++ b/src/Symfony/Component/VarDumper/Caster/Caster.php @@ -195,7 +195,7 @@ private static function getClassProperties(\ReflectionClass $class): array $p->isPublic() => $p->name, $p->isProtected() => self::PREFIX_PROTECTED.$p->name, default => "\0".$className."\0".$p->name, - }] = \PHP_VERSION_ID >= 80400 && $p->isVirtual() ? new VirtualStub($p) : new UninitializedStub($p); + }] = $p->isVirtual() ? new VirtualStub($p) : new UninitializedStub($p); } return $classProperties; diff --git a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php index e7310f404ef4a..923a671e0d91b 100644 --- a/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php @@ -119,14 +119,9 @@ public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $ public static function castAttribute(\ReflectionAttribute $c, array $a, Stub $stub, bool $isNested): array { $map = [ - 'name' => 'getName', 'arguments' => 'getArguments', ]; - if (\PHP_VERSION_ID >= 80400) { - unset($map['name']); - } - self::addMap($a, $c, $map); return $a; diff --git a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php index 5613c5534cd5f..981f62ce13d90 100644 --- a/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/ResourceCaster.php @@ -34,12 +34,9 @@ public static function castCurl(\CurlHandle $h, array $a, Stub $stub, bool $isNe return CurlCaster::castCurl($h, $a, $stub, $isNested); } - /** - * @param resource|\Dba\Connection $dba - */ - public static function castDba(mixed $dba, array $a, Stub $stub, bool $isNested): array + public static function castDba(\Dba\Connection $dba, array $a, Stub $stub, bool $isNested): array { - if (\PHP_VERSION_ID < 80402 && !\is_resource($dba)) { + if (\PHP_VERSION_ID < 80402) { // @see https://github.com/php/php-src/issues/16990 return $a; } diff --git a/src/Symfony/Component/VarDumper/Caster/SocketCaster.php b/src/Symfony/Component/VarDumper/Caster/SocketCaster.php index 6b95cd10ed0e1..e35ba5dc0f8e9 100644 --- a/src/Symfony/Component/VarDumper/Caster/SocketCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/SocketCaster.php @@ -26,19 +26,17 @@ public static function castSocket(\Socket $socket, array $a, Stub $stub, bool $i socket_getsockname($socket, $addr, $port); $info = stream_get_meta_data(socket_export_stream($socket)); - if (\PHP_VERSION_ID >= 80300) { - $uri = ($info['uri'] ?? '//'); - if (str_starts_with($uri, 'unix://')) { - $uri .= $addr; - } else { - $uri .= \sprintf(str_contains($addr, ':') ? '[%s]:%s' : '%s:%s', $addr, $port); - } + $uri = ($info['uri'] ?? '//'); + if (str_starts_with($uri, 'unix://')) { + $uri .= $addr; + } else { + $uri .= \sprintf(str_contains($addr, ':') ? '[%s]:%s' : '%s:%s', $addr, $port); + } - $a[Caster::PREFIX_VIRTUAL.'uri'] = $uri; + $a[Caster::PREFIX_VIRTUAL.'uri'] = $uri; - if (@socket_atmark($socket)) { - $a[Caster::PREFIX_VIRTUAL.'atmark'] = true; - } + if (@socket_atmark($socket)) { + $a[Caster::PREFIX_VIRTUAL.'atmark'] = true; } $a += [ diff --git a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php index 9038d2c04e8a5..3befdf6c60a34 100644 --- a/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php +++ b/src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php @@ -180,8 +180,6 @@ abstract class AbstractCloner implements ClonerInterface 'CurlHandle' => ['Symfony\Component\VarDumper\Caster\CurlCaster', 'castCurl'], 'Dba\Connection' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], - ':dba' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], - ':dba persistent' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'], 'GdImage' => ['Symfony\Component\VarDumper\Caster\ResourceCaster', 'castGd'], diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php index 7b79939bfdd75..a9ad85ce1c1c2 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/DOMCasterTest.php @@ -32,9 +32,6 @@ public function testCastImplementation() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernImplementation() { $implementation = new \Dom\Implementation(); @@ -49,30 +46,6 @@ public function testCastModernImplementation() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastNodePriorToPhp84() - { - $doc = new \DOMDocument(); - $doc->loadXML(''); - $node = $doc->documentElement->firstChild; - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMElement {%A - +ownerDocument: ? ?DOMDocument - +namespaceURI: ? ?string - +prefix: ? string - +localName: ? ?string - %A} - EODUMP, - $node - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastNode() { $doc = new \DOMDocument(); @@ -91,9 +64,6 @@ public function testCastNode() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernNode() { $doc = \Dom\XMLDocument::createFromString(''); @@ -129,9 +99,6 @@ public function testCastDocument() ); } - /** - * @requires PHP 8.4 - */ public function testCastXMLDocument() { $doc = \Dom\XMLDocument::createFromString(''); @@ -150,9 +117,6 @@ public function testCastXMLDocument() ); } - /** - * @requires PHP 8.4 - */ public function testCastHTMLDocument() { $doc = \Dom\HTMLDocument::createFromString('

foo

'); @@ -166,25 +130,6 @@ public function testCastHTMLDocument() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastTextPriorToPhp84() - { - $doc = new \DOMText('foo'); - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMText {%A - +wholeText: ? string - } - EODUMP, - $doc - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastText() { $doc = new \DOMText('foo'); @@ -198,9 +143,6 @@ public function testCastText() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernText() { $text = \Dom\HTMLDocument::createEmpty()->createTextNode('foo'); @@ -213,29 +155,6 @@ public function testCastModernText() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastAttrPriorToPhp84() - { - $attr = new \DOMAttr('attr', 'value'); - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMAttr {%A - +name: ? string - +specified: true - +value: ? string - +ownerElement: ? ?DOMElement - +schemaTypeInfo: null - } - EODUMP, - $attr - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastAttr() { $attr = new \DOMAttr('attr', 'value'); @@ -253,9 +172,6 @@ public function testCastAttr() ); } - /** - * @requires PHP 8.4 - */ public function testCastAttrPrior() { $attr = new \DOMAttr('attr', 'value'); @@ -273,9 +189,6 @@ public function testCastAttrPrior() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernAttr() { $attr = \Dom\HTMLDocument::createEmpty()->createAttribute('attr'); @@ -292,25 +205,6 @@ public function testCastModernAttr() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastElementPriorToPhp84() - { - $attr = new \DOMElement('foo'); - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMElement {%A - +tagName: ? string - %A} - EODUMP, - $attr - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastElement() { $attr = new \DOMElement('foo'); @@ -324,9 +218,6 @@ public function testCastElement() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernElement() { $attr = \Dom\HTMLDocument::createEmpty()->createElement('foo'); @@ -340,31 +231,6 @@ public function testCastModernElement() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastDocumentTypePriorToPhp84() - { - $implementation = new \DOMImplementation(); - $type = $implementation->createDocumentType('html', 'publicId', 'systemId'); - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMDocumentType {%A - +name: ? string - +entities: ? DOMNamedNodeMap - +notations: ? DOMNamedNodeMap - +publicId: ? string - +systemId: ? string - +internalSubset: ? ?string - } - EODUMP, - $type - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastDocumentType() { $implementation = new \DOMImplementation(); @@ -384,9 +250,6 @@ public function testCastDocumentType() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernDocumentType() { $implementation = new \Dom\Implementation(); @@ -406,26 +269,6 @@ public function testCastModernDocumentType() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastProcessingInstructionPriorToPhp84() - { - $entity = new \DOMProcessingInstruction('target', 'data'); - - $this->assertDumpMatchesFormat(<<<'EODUMP' - DOMProcessingInstruction {%A - +target: ? string - +data: ? string - } - EODUMP, - $entity - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastProcessingInstruction() { $entity = new \DOMProcessingInstruction('target', 'data'); @@ -440,9 +283,6 @@ public function testCastProcessingInstruction() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernProcessingInstruction() { $entity = \Dom\HTMLDocument::createEmpty()->createProcessingInstruction('target', 'data'); @@ -458,26 +298,6 @@ public function testCastModernProcessingInstruction() ); } - /** - * @requires PHP < 8.4 - */ - public function testCastXPathPriorToPhp84() - { - $xpath = new \DOMXPath(new \DOMDocument()); - - $this->assertDumpEquals(<<<'EODUMP' - DOMXPath { - +document: ? DOMDocument - +registerNodeNamespaces: ? bool - } - EODUMP, - $xpath - ); - } - - /** - * @requires PHP 8.4 - */ public function testCastXPath() { $xpath = new \DOMXPath(new \DOMDocument()); @@ -492,9 +312,6 @@ public function testCastXPath() ); } - /** - * @requires PHP 8.4 - */ public function testCastModernXPath() { $entity = new \Dom\XPath(\Dom\HTMLDocument::createEmpty()); diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php index c6a96ec37069b..19ed360fb3060 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/PdoCasterTest.php @@ -43,8 +43,7 @@ public function testCastPdo() $this->assertSame('NATURAL', $attr['CASE']->class); $this->assertSame('BOTH', $attr['DEFAULT_FETCH_MODE']->class); - if (\PHP_VERSION_ID >= 80215 && \PHP_VERSION_ID < 80300 || \PHP_VERSION_ID >= 80302) { - $xDump = <<<'EODUMP' + $xDump = <<<'EODUMP' array:2 [ "\x00~\x00inTransaction" => false "\x00~\x00attributes" => array:10 [ @@ -63,26 +62,6 @@ public function testCastPdo() ] ] EODUMP; - } else { - $xDump = <<<'EODUMP' -array:2 [ - "\x00~\x00inTransaction" => false - "\x00~\x00attributes" => array:9 [ - "CASE" => NATURAL - "ERRMODE" => EXCEPTION - "PERSISTENT" => false - "DRIVER_NAME" => "sqlite" - "ORACLE_NULLS" => NATURAL - "CLIENT_VERSION" => "%s" - "SERVER_VERSION" => "%s" - "STATEMENT_CLASS" => array:%d [ - 0 => "PDOStatement"%A - ] - "DEFAULT_FETCH_MODE" => BOTH - ] -] -EODUMP; - } $this->assertDumpMatchesFormat($xDump, $cast); } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php index 83dad9e174ead..958d2b3a6836b 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php @@ -404,9 +404,6 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest" ); } - /** - * @requires PHP 8.2 - */ public function testNullReturnType() { $className = Php82NullStandaloneReturnType::class; @@ -460,84 +457,6 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest" ); } - /** - * @requires PHP < 8.4 - */ - public function testGeneratorPriorTo84() - { - if (\extension_loaded('xdebug')) { - $this->markTestSkipped('xdebug is active'); - } - - $generator = new GeneratorDemo(); - $generator = $generator->baz(); - - $expectedDump = <<<'EODUMP' -Generator { - this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …} - %s: { - %sGeneratorDemo.php:14 { - Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() - › { - › yield from bar(); - › } - } -%A} - closed: false -} -EODUMP; - - $this->assertDumpMatchesFormat($expectedDump, $generator); - - foreach ($generator as $v) { - break; - } - - $expectedDump = <<<'EODUMP' -array:2 [ - 0 => ReflectionGenerator { - this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …} - %s: { - %s%eTests%eFixtures%eGeneratorDemo.php:%d { - Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() -%A › yield 1; -%A } - %s%eTests%eFixtures%eGeneratorDemo.php:20 { …} - %s%eTests%eFixtures%eGeneratorDemo.php:14 { …} -%A } - closed: false - } - 1 => Generator { - %s: { - %s%eTests%eFixtures%eGeneratorDemo.php:%d { - Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() - › yield 1; - › } - › - } -%A } - closed: false - } -] -EODUMP; - - $r = new \ReflectionGenerator($generator); - $this->assertDumpMatchesFormat($expectedDump, [$r, $r->getExecutingGenerator()]); - - foreach ($generator as $v) { - } - - $expectedDump = <<<'EODUMP' -Generator { - closed: true -} -EODUMP; - $this->assertDumpMatchesFormat($expectedDump, $generator); - } - - /** - * @requires PHP 8.4 - */ public function testGenerator() { if (\extension_loaded('xdebug')) { @@ -636,14 +555,13 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest" public function testReflectionClassWithAttribute() { $var = new \ReflectionClass(LotsOfAttributes::class); - $dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name'; $this->assertDumpMatchesFormat(<< ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" arguments: [] } ] @@ -656,7 +574,6 @@ public function testReflectionClassWithAttribute() public function testReflectionMethodWithAttribute() { $var = new \ReflectionMethod(LotsOfAttributes::class, 'someMethod'); - $dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name'; $this->assertDumpMatchesFormat(<< ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" arguments: array:1 [ 0 => "two" ] @@ -679,7 +596,6 @@ public function testReflectionMethodWithAttribute() public function testReflectionPropertyWithAttribute() { $var = new \ReflectionProperty(LotsOfAttributes::class, 'someProperty'); - $dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name'; $this->assertDumpMatchesFormat(<< ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" arguments: array:2 [ 0 => "one" "extra" => "hello" @@ -702,7 +618,6 @@ public function testReflectionPropertyWithAttribute() public function testReflectionClassConstantWithAttribute() { $var = new \ReflectionClassConstant(LotsOfAttributes::class, 'SOME_CONSTANT'); - $dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name'; $this->assertDumpMatchesFormat(<< ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute" arguments: array:1 [ 0 => "one" ] } 1 => ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\RepeatableAttribute" arguments: array:1 [ 0 => "two" ] @@ -732,15 +647,14 @@ public function testReflectionClassConstantWithAttribute() public function testReflectionParameterWithAttribute() { $var = new \ReflectionParameter([LotsOfAttributes::class, 'someMethod'], 'someParameter'); - $dumpedAttributeNameProperty = (\PHP_VERSION_ID < 80400 ? '' : '+').'name'; - + $this->assertDumpMatchesFormat(<< ReflectionAttribute { - $dumpedAttributeNameProperty: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" + +name: "Symfony\Component\VarDumper\Tests\Fixtures\MyAttribute" arguments: array:1 [ 0 => "three" ] diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php index 6fd3762b9102d..1bfd47f488e18 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/ResourceCasterTest.php @@ -52,22 +52,6 @@ public function testCastGdIsDeprecated() ResourceCaster::castGd($gd, [], new Stub(), false); } - /** - * @requires PHP < 8.4 - * @requires extension dba - */ - public function testCastDbaPriorToPhp84() - { - $dba = dba_open(sys_get_temp_dir().'/test.db', 'c'); - - $this->assertDumpMatchesFormat( - <<<'EODUMP' -dba resource { - file: %s -} -EODUMP, $dba); - } - /** * @requires extension dba */ diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/SocketCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/SocketCasterTest.php index 741a9ddd5f92e..82b8eb3bd0d10 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/SocketCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/SocketCasterTest.php @@ -21,9 +21,6 @@ class SocketCasterTest extends TestCase { use VarDumperTestTrait; - /** - * @requires PHP 8.3 - */ public function testCastSocket() { $socket = socket_create(\AF_INET, \SOCK_DGRAM, \SOL_UDP); @@ -39,26 +36,6 @@ public function testCastSocket() EODUMP, $socket); } - /** - * @requires PHP < 8.3 - */ - public function testCastSocketPriorToPhp83() - { - $socket = socket_create(\AF_INET, \SOCK_DGRAM, \SOL_UDP); - @socket_connect($socket, '127.0.0.1', 80); - - $this->assertDumpMatchesFormat( - <<<'EODUMP' -Socket { - timed_out: false - blocked: true -} -EODUMP, $socket); - } - - /** - * @requires PHP 8.3 - */ public function testCastSocketIpV6() { $socket = socket_create(\AF_INET6, \SOCK_STREAM, \SOL_TCP); @@ -75,27 +52,6 @@ public function testCastSocketIpV6() EODUMP, $socket); } - /** - * @requires PHP < 8.3 - */ - public function testCastSocketIpV6PriorToPhp83() - { - $socket = socket_create(\AF_INET6, \SOCK_STREAM, \SOL_TCP); - @socket_connect($socket, '::1', 80); - - $this->assertDumpMatchesFormat( - <<<'EODUMP' -Socket { - timed_out: false - blocked: true - last_error: SOCKET_ECONNREFUSED -} -EODUMP, $socket); - } - - /** - * @requires PHP 8.3 - */ public function testCastUnixSocket() { $socket = socket_create(\AF_UNIX, \SOCK_STREAM, 0); @@ -109,24 +65,6 @@ public function testCastUnixSocket() blocked: true last_error: SOCKET_ENOENT } -EODUMP, $socket); - } - - /** - * @requires PHP < 8.3 - */ - public function testCastUnixSocketPriorToPhp83() - { - $socket = socket_create(\AF_UNIX, \SOCK_STREAM, 0); - @socket_connect($socket, '/tmp/socket.sock'); - - $this->assertDumpMatchesFormat( - <<<'EODUMP' -Socket { - timed_out: false - blocked: true - last_error: SOCKET_ENOENT -} EODUMP, $socket); } } diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php index 1f76900d489e2..e5e369f0a262a 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/StubCasterTest.php @@ -103,9 +103,6 @@ public function testEmptyStub() $this->assertDumpMatchesFormat($expectedDump, $args); } - /** - * @requires PHP 8.4 - */ public function testVirtualPropertyStub() { $class = new \ReflectionClass(VirtualProperty::class); @@ -120,9 +117,6 @@ public function testVirtualPropertyStub() $this->assertDumpMatchesFormat($expectedDump, $args); } - /** - * @requires PHP 8.4 - */ public function testVirtualPropertyWithoutTypeStub() { $class = new \ReflectionClass(VirtualProperty::class); @@ -253,7 +247,7 @@ public function testClassStubWithAnonymousClass() $expectedDump = <<<'EODUMP' array:1 [ - 0 => "Exception@anonymous" + 0 => "Exception@anonymous" ] EODUMP; diff --git a/src/Symfony/Component/VarDumper/Tests/Caster/XmlReaderCasterTest.php b/src/Symfony/Component/VarDumper/Tests/Caster/XmlReaderCasterTest.php index 67feddba0f542..99790a4711a01 100644 --- a/src/Symfony/Component/VarDumper/Tests/Caster/XmlReaderCasterTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Caster/XmlReaderCasterTest.php @@ -34,30 +34,6 @@ protected function tearDown(): void $this->reader->close(); } - /** - * @requires PHP < 8.4 - */ - public function testParserPropertyPriorToPhp84() - { - $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true); - - $expectedDump = <<<'EODUMP' -XMLReader { - +nodeType: NONE - parserProperties: { - SUBST_ENTITIES: true - …3 - } - …12 -} -EODUMP; - - $this->assertDumpMatchesFormat($expectedDump, $this->reader); - } - - /** - * @requires PHP 8.4 - */ public function testParserProperty() { $this->reader->setParserProperty(\XMLReader::SUBST_ENTITIES, true); @@ -77,22 +53,6 @@ public function testParserProperty() $this->assertDumpMatchesFormat($expectedDump, $this->reader); } - /** - * This test only work before PHP 8.4. In PHP 8.4, XMLReader properties are virtual - * and their values are not dumped. - * - * @requires PHP < 8.4 - * - * @dataProvider provideNodes - */ - public function testNodes($seek, $expectedDump) - { - while ($seek--) { - $this->reader->read(); - } - $this->assertDumpMatchesFormat($expectedDump, $this->reader); - } - public static function provideNodes() { return [ @@ -275,26 +235,6 @@ public static function provideNodes() ]; } - /** - * @requires PHP < 8.4 - */ - public function testWithUninitializedXMLReaderPriorToPhp84() - { - $this->reader = new \XMLReader(); - - $expectedDump = <<<'EODUMP' -XMLReader { - +nodeType: NONE - …13 -} -EODUMP; - - $this->assertDumpMatchesFormat($expectedDump, $this->reader); - } - - /** - * @requires PHP 8.4 - */ public function testWithUninitializedXMLReader() { $this->reader = new \XMLReader(); diff --git a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php index 14b538084b50c..a58d7a98aa564 100644 --- a/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php +++ b/src/Symfony/Component/VarDumper/Tests/Dumper/CliDumperTest.php @@ -305,9 +305,6 @@ public function testFlags() putenv('DUMP_STRING_LENGTH='); } - /** - * @requires PHP 8.4 - */ public function testVirtualProperties() { $this->assertDumpEquals(<< $v) { $p = $reflector->hasProperty($n) ? $reflector->getProperty($n) : null; - $c = $p && (\PHP_VERSION_ID >= 80400 ? $p->isProtectedSet() || $p->isPrivateSet() : $p->isReadOnly()) ? $p->class : 'stdClass'; + $c = $p && ($p->isProtectedSet() || $p->isPrivateSet()) ? $p->class : 'stdClass'; $properties[$c][$n] = $v; } } @@ -145,7 +145,7 @@ public static function prepare($values, $objectsPool, &$refsPool, &$objectsCount $n = (string) $name; if ('' === $n || "\0" !== $n[0]) { $p = $reflector->hasProperty($n) ? $reflector->getProperty($n) : null; - $c = $p && (\PHP_VERSION_ID >= 80400 ? $p->isProtectedSet() || $p->isPrivateSet() : $p->isReadOnly()) ? $p->class : 'stdClass'; + $c = $p && ($p->isProtectedSet() || $p->isPrivateSet()) ? $p->class : 'stdClass'; } elseif ('*' === $n[1]) { $n = substr($n, 3); $c = $reflector->getProperty($n)->class; diff --git a/src/Symfony/Component/VarExporter/Internal/Hydrator.php b/src/Symfony/Component/VarExporter/Internal/Hydrator.php index 450935e5bdaa3..96c55eaff6e53 100644 --- a/src/Symfony/Component/VarExporter/Internal/Hydrator.php +++ b/src/Symfony/Component/VarExporter/Internal/Hydrator.php @@ -222,7 +222,7 @@ public static function getSimpleHydrator($class) if ($propertyReflector->isStatic()) { continue; } - if (\PHP_VERSION_ID >= 80400 && !$propertyReflector->isAbstract() && $propertyReflector->getHooks()) { + if (!$propertyReflector->isAbstract() && $propertyReflector->getHooks()) { $notByRef->{$propertyReflector->name} = $propertyReflector->setRawValue(...); } elseif ($propertyReflector->isReadOnly()) { $notByRef->{$propertyReflector->name} = true; @@ -273,7 +273,7 @@ public static function getPropertyScopes($class): array $name = $property->name; $access = ($flags << 2) | ($flags & \ReflectionProperty::IS_READONLY ? self::PROPERTY_NOT_BY_REF : 0); - if (\PHP_VERSION_ID >= 80400 && !$property->isAbstract() && $h = $property->getHooks()) { + if (!$property->isAbstract() && $h = $property->getHooks()) { $access |= self::PROPERTY_HAS_HOOKS | (isset($h['get']) && !$h['get']->returnsReference() ? self::PROPERTY_NOT_BY_REF : 0); } @@ -285,7 +285,7 @@ public static function getPropertyScopes($class): array $propertyScopes[$name] = [$class, $name, null, $access, $property]; - if ($flags & (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET : \ReflectionProperty::IS_READONLY)) { + if ($flags & \ReflectionProperty::IS_PRIVATE_SET) { $propertyScopes[$name][2] = $property->class; } @@ -306,7 +306,7 @@ public static function getPropertyScopes($class): array $name = $property->name; $access = ($flags << 2) | ($flags & \ReflectionProperty::IS_READONLY ? self::PROPERTY_NOT_BY_REF : 0); - if (\PHP_VERSION_ID >= 80400 && $h = $property->getHooks()) { + if ($h = $property->getHooks()) { $access |= self::PROPERTY_HAS_HOOKS | (isset($h['get']) && !$h['get']->returnsReference() ? self::PROPERTY_NOT_BY_REF : 0); } diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php index a2034258f0c8c..cb812cc092d7c 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectRegistry.php @@ -145,7 +145,7 @@ public static function getScopeForRead($propertyScopes, $class, $property) public static function getScopeForWrite($propertyScopes, $class, $property, $flags) { - if (!($flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_READONLY | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET | \ReflectionProperty::IS_PROTECTED_SET : 0)))) { + if (!($flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_READONLY | \ReflectionProperty::IS_PRIVATE_SET))) { return null; } $frame = debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]; @@ -153,10 +153,10 @@ public static function getScopeForWrite($propertyScopes, $class, $property, $fla if (\ReflectionProperty::class === $scope = $frame['class'] ?? \Closure::class) { $scope = $frame['object']->class; } - if ($flags & (\ReflectionProperty::IS_PRIVATE | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PRIVATE_SET : \ReflectionProperty::IS_READONLY))) { + if ($flags & (\ReflectionProperty::IS_PRIVATE | \ReflectionProperty::IS_PRIVATE_SET)) { return $scope; } - if ($flags & (\ReflectionProperty::IS_PROTECTED | (\PHP_VERSION_ID >= 80400 ? \ReflectionProperty::IS_PROTECTED_SET : 0)) && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { + if ($flags & (\ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PROTECTED_SET) && ($class === $scope || (is_subclass_of($class, $scope) && !isset($propertyScopes["\0$scope\0$property"])))) { return null; } diff --git a/src/Symfony/Component/VarExporter/Internal/LazyObjectTrait.php b/src/Symfony/Component/VarExporter/Internal/LazyObjectTrait.php index 4a6f232af85ab..bf1d989efc97f 100644 --- a/src/Symfony/Component/VarExporter/Internal/LazyObjectTrait.php +++ b/src/Symfony/Component/VarExporter/Internal/LazyObjectTrait.php @@ -12,23 +12,12 @@ namespace Symfony\Component\VarExporter\Internal; use Symfony\Component\Serializer\Attribute\Ignore; - -if (\PHP_VERSION_ID >= 80300) { - /** - * @internal - */ - trait LazyObjectTrait - { - #[Ignore] - private readonly LazyObjectState $lazyObjectState; - } -} else { - /** - * @internal - */ - trait LazyObjectTrait - { - #[Ignore] - private LazyObjectState $lazyObjectState; - } +/** + * @internal + * @deprecated since Symfony 7.3 + */ +trait LazyObjectTrait +{ + #[Ignore] + private readonly LazyObjectState $lazyObjectState; } diff --git a/src/Symfony/Component/VarExporter/LazyGhostTrait.php b/src/Symfony/Component/VarExporter/LazyGhostTrait.php index 529ace2e9f555..86e3e3f49bc7a 100644 --- a/src/Symfony/Component/VarExporter/LazyGhostTrait.php +++ b/src/Symfony/Component/VarExporter/LazyGhostTrait.php @@ -17,9 +17,7 @@ use Symfony\Component\VarExporter\Internal\LazyObjectState; use Symfony\Component\VarExporter\Internal\LazyObjectTrait; -if (\PHP_VERSION_ID >= 80400) { - trigger_deprecation('symfony/var-exporter', '7.3', 'The "%s" trait is deprecated, use native lazy objects instead.', LazyGhostTrait::class); -} +trigger_deprecation('symfony/var-exporter', '7.3', 'The "%s" trait is deprecated, use native lazy objects instead.', LazyGhostTrait::class); /** * @deprecated since Symfony 7.3, use native lazy objects instead @@ -146,7 +144,7 @@ public function &__get($name): mixed } else { $property = null; } - if (\PHP_VERSION_ID >= 80400 && !$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { + if (!$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { $scope ??= $writeScope; } diff --git a/src/Symfony/Component/VarExporter/LazyProxyTrait.php b/src/Symfony/Component/VarExporter/LazyProxyTrait.php index fc28c1d2a5e08..5aacde7b1c18b 100644 --- a/src/Symfony/Component/VarExporter/LazyProxyTrait.php +++ b/src/Symfony/Component/VarExporter/LazyProxyTrait.php @@ -18,9 +18,7 @@ use Symfony\Component\VarExporter\Internal\LazyObjectState; use Symfony\Component\VarExporter\Internal\LazyObjectTrait; -if (\PHP_VERSION_ID >= 80400) { - trigger_deprecation('symfony/var-exporter', '7.3', 'The "%s" trait is deprecated, use native lazy objects instead.', LazyProxyTrait::class); -} +trigger_deprecation('symfony/var-exporter', '7.3', 'The "%s" trait is deprecated, use native lazy objects instead.', LazyProxyTrait::class); /** * @deprecated since Symfony 7.3, use native lazy objects instead @@ -123,7 +121,7 @@ public function &__get($name): mixed if ($state = $this->lazyObjectState ?? null) { $instance = $state->realInstance ??= ($state->initializer)(); } - if (\PHP_VERSION_ID >= 80400 && !$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { + if (!$notByRef && ($access >> 2) & \ReflectionProperty::IS_PRIVATE_SET) { $scope ??= $writeScope; } $parent = 2; diff --git a/src/Symfony/Component/VarExporter/ProxyHelper.php b/src/Symfony/Component/VarExporter/ProxyHelper.php index b815e7040c501..a52aba295cb0d 100644 --- a/src/Symfony/Component/VarExporter/ProxyHelper.php +++ b/src/Symfony/Component/VarExporter/ProxyHelper.php @@ -30,12 +30,6 @@ final class ProxyHelper */ 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)); } @@ -138,9 +132,6 @@ public static function generateLazyProxy(?\ReflectionClass $class, array $interf if ($class?->isFinal()) { throw new LogicException(\sprintf('Cannot generate lazy proxy: class "%s" is final.', $class->name)); } - if (\PHP_VERSION_ID < 80400) { - return self::generateLegacyLazyProxy($class, $interfaces); - } if ($class && !$class->isAbstract()) { $parent = $class; @@ -376,156 +367,6 @@ class_exists(\Symfony\Component\VarExporter\Internal\LazyObjectRegistry::class); EOPHP; } - private static function generateLegacyLazyProxy(?\ReflectionClass $class, array $interfaces): string - { - if (\PHP_VERSION_ID < 80300 && $class?->isReadOnly()) { - throw new LogicException(\sprintf('Cannot generate lazy proxy with PHP < 8.3: class "%s" is readonly.', $class->name)); - } - - $propertyScopes = $class ? Hydrator::$propertyScopes[$class->name] ??= Hydrator::getPropertyScopes($class->name) : []; - $methodReflectors = [$class?->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) ?? []]; - foreach ($interfaces as $interface) { - if (!$interface->isInterface()) { - throw new LogicException(\sprintf('Cannot generate lazy proxy: "%s" is not an interface.', $interface->name)); - } - $methodReflectors[] = $interface->getMethods(); - } - - $extendsInternalClass = false; - if ($parent = $class) { - do { - $extendsInternalClass = \stdClass::class !== $parent->name && $parent->isInternal(); - } while (!$extendsInternalClass && $parent = $parent->getParentClass()); - } - $methodsHaveToBeProxied = $extendsInternalClass; - $methods = []; - $methodReflectors = array_merge(...$methodReflectors); - - foreach ($methodReflectors as $method) { - if ('__get' !== strtolower($method->name) || 'mixed' === ($type = self::exportType($method) ?? 'mixed')) { - continue; - } - $methodsHaveToBeProxied = true; - $trait = new \ReflectionMethod(LazyProxyTrait::class, '__get'); - $body = \array_slice(file($trait->getFileName()), $trait->getStartLine() - 1, $trait->getEndLine() - $trait->getStartLine()); - $body[0] = str_replace('): mixed', '): '.$type, $body[0]); - $methods['__get'] = strtr(implode('', $body).' }', [ - 'Hydrator' => '\\'.Hydrator::class, - 'Registry' => '\\'.LazyObjectRegistry::class, - ]); - break; - } - - foreach ($methodReflectors as $method) { - if (($method->isStatic() && !$method->isAbstract()) || isset($methods[$lcName = strtolower($method->name)])) { - continue; - } - if ($method->isFinal()) { - if ($extendsInternalClass || $methodsHaveToBeProxied || method_exists(LazyProxyTrait::class, $method->name)) { - throw new LogicException(\sprintf('Cannot generate lazy proxy: method "%s::%s()" is final.', $class->name, $method->name)); - } - continue; - } - if (method_exists(LazyProxyTrait::class, $method->name) || ($method->isProtected() && !$method->isAbstract())) { - continue; - } - - $signature = self::exportSignature($method, true, $args); - $parentCall = $method->isAbstract() ? "throw new \BadMethodCallException('Cannot forward abstract method \"{$method->class}::{$method->name}()\".')" : "parent::{$method->name}({$args})"; - - if ($method->isStatic()) { - $body = " $parentCall;"; - } elseif (str_ends_with($signature, '): never') || str_ends_with($signature, '): void')) { - $body = <<lazyObjectState)) { - (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args}); - } else { - {$parentCall}; - } - EOPHP; - } else { - if (!$methodsHaveToBeProxied && !$method->isAbstract()) { - // Skip proxying methods that might return $this - foreach (preg_split('/[()|&]++/', self::exportType($method) ?? 'static') as $type) { - if (\in_array($type = ltrim($type, '?'), ['static', 'object'], true)) { - continue 2; - } - foreach ([$class, ...$interfaces] as $r) { - if ($r && is_a($r->name, $type, true)) { - continue 3; - } - } - } - } - - $body = <<lazyObjectState)) { - return (\$this->lazyObjectState->realInstance ??= (\$this->lazyObjectState->initializer)())->{$method->name}({$args}); - } - - return {$parentCall}; - EOPHP; - } - $methods[$lcName] = " {$signature}\n {\n{$body}\n }"; - } - - $types = $interfaces = array_unique(array_column($interfaces, 'name')); - $interfaces[] = LazyObjectInterface::class; - $interfaces = implode(', \\', $interfaces); - $parent = $class ? ' extends \\'.$class->name : ''; - array_unshift($types, $class ? 'parent' : ''); - $type = ltrim(implode('&\\', $types), '&'); - - if (!$class) { - $trait = new \ReflectionMethod(LazyProxyTrait::class, 'initializeLazyObject'); - $body = \array_slice(file($trait->getFileName()), $trait->getStartLine() - 1, $trait->getEndLine() - $trait->getStartLine()); - $body[0] = str_replace('): parent', '): '.$type, $body[0]); - $methods = ['initializeLazyObject' => implode('', $body).' }'] + $methods; - } - $body = $methods ? "\n".implode("\n\n", $methods)."\n" : ''; - $propertyScopes = $class ? self::exportPropertyScopes($class->name, $propertyScopes) : '[]'; - - if ( - $class?->hasMethod('__unserialize') - && !$class->getMethod('__unserialize')->getParameters()[0]->getType() - ) { - // fix contravariance type problem when $class declares a `__unserialize()` method without typehint. - $lazyProxyTraitStatement = <<__doUnserialize(\$data); - } - - EOPHP; - } else { - $lazyProxyTraitStatement = <<assertSame(\PHP_VERSION_ID >= 80400 ? 1 : 0, $initCounter); + $this->assertSame(1, $initCounter); $dep1 = $proxy->getDep(); - $this->assertSame(\PHP_VERSION_ID >= 80400 ? 1 : 1, $initCounter); + $this->assertSame(1, $initCounter); $dep2 = $clone->getDep(); - $this->assertSame(\PHP_VERSION_ID >= 80400 ? 1 : 2, $initCounter); + $this->assertSame(1, $initCounter); - $this->assertSame(\PHP_VERSION_ID >= 80400, $dep1 === $dep2); + $this->assertSame($dep1, $dep2); } public function testUnserialize() @@ -223,7 +220,7 @@ public function withFoo($foo): static $clone = $proxy->withFoo(234); $this->assertSame($clone::class, $proxy::class); $this->assertSame(234, $clone->foo); - $this->assertSame(\PHP_VERSION_ID >= 80400 ? 123 : 234, $obj->foo); + $this->assertSame(123, $obj->foo); } public function testFluent() @@ -258,11 +255,6 @@ public function testIndirectModification() public function testReadOnlyClass() { - if (\PHP_VERSION_ID < 80300) { - $this->expectException(LogicException::class); - $this->expectExceptionMessage('Cannot generate lazy proxy with PHP < 8.3: class "Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\ReadOnlyClass" is readonly.'); - } - $proxy = $this->createLazyProxy(ReadOnlyClass::class, fn () => new ConcreteReadOnlyClass(123)); $this->assertSame(123, $proxy->foo); @@ -292,9 +284,6 @@ public function testReinitRegularLazyProxy() $this->assertSame(234, $object->foo); } - /** - * @requires PHP 8.3 - */ public function testReinitReadonlyLazyProxy() { $object = $this->createLazyProxy(ReadOnlyClass::class, fn () => new ConcreteReadOnlyClass(123)); @@ -306,9 +295,6 @@ public function testReinitReadonlyLazyProxy() $this->assertSame(234, $object->foo); } - /** - * @requires PHP 8.4 - */ public function testConcretePropertyHooks() { $initialized = false; @@ -335,9 +321,6 @@ public function testConcretePropertyHooks() $this->assertSame(345, $object->backed); } - /** - * @requires PHP 8.4 - */ public function testAbstractPropertyHooks() { $initialized = false; @@ -369,9 +352,6 @@ public function testAbstractPropertyHooks() $this->assertTrue($initialized); } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibility() { $object = $this->createLazyProxy(AsymmetricVisibility::class, function () { diff --git a/src/Symfony/Component/VarExporter/Tests/LegacyLazyGhostTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LegacyLazyGhostTraitTest.php index c650626847055..1683a3c799834 100644 --- a/src/Symfony/Component/VarExporter/Tests/LegacyLazyGhostTraitTest.php +++ b/src/Symfony/Component/VarExporter/Tests/LegacyLazyGhostTraitTest.php @@ -241,9 +241,6 @@ public function testIndirectModification() $this->assertSame([123], $proxy->foo); } - /** - * @requires PHP 8.3 - */ public function testReadOnlyClass() { $proxy = $this->createLazyGhost(ReadOnlyClass::class, fn ($proxy) => $proxy->__construct(123)); @@ -297,9 +294,6 @@ public function testReinitLazyGhost() $this->assertSame(3, $object->public); } - /** - * @requires PHP 8.4 - */ public function testPropertyHooks() { $initialized = false; @@ -322,9 +316,6 @@ public function testPropertyHooks() $this->assertSame(345, $object->backed); } - /** - * @requires PHP 8.4 - */ public function testPropertyHooksWithDefaultValue() { $initialized = false; @@ -350,9 +341,6 @@ public function testPropertyHooksWithDefaultValue() $this->assertSame(true, $object->backedBoolWithDefault); } - /** - * @requires PHP 8.4 - */ public function testAsymmetricVisibility() { $object = $this->createLazyGhost(AsymmetricVisibility::class, function ($instance) { diff --git a/src/Symfony/Component/VarExporter/Tests/LegacyLazyProxyTraitTest.php b/src/Symfony/Component/VarExporter/Tests/LegacyLazyProxyTraitTest.php deleted file mode 100644 index 383b08fe82e22..0000000000000 --- a/src/Symfony/Component/VarExporter/Tests/LegacyLazyProxyTraitTest.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\VarExporter\Tests; - -use Symfony\Component\VarExporter\LazyProxyTrait; -use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\FinalPublicClass; -use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestClass; -use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\TestOverwritePropClass; - -/** - * @requires PHP < 8.4 - * - * @group legacy - */ -class LegacyLazyProxyTraitTest extends LazyProxyTraitTest -{ - public function testLazyDecoratorClass() - { - $obj = new class extends TestClass { - use LazyProxyTrait { - createLazyProxy as private; - } - - public function __construct() - { - self::createLazyProxy(fn () => new TestClass((object) ['foo' => 123]), $this); - } - }; - - $this->assertSame(['foo' => 123], (array) $obj->getDep()); - } - - public function testFinalPublicClass() - { - $proxy = $this->createLazyProxy(FinalPublicClass::class, fn () => new FinalPublicClass()); - - $this->assertSame(1, $proxy->increment()); - $this->assertSame(2, $proxy->increment()); - $this->assertSame(1, $proxy->decrement()); - } - - public function testOverwritePropClass() - { - $proxy = $this->createLazyProxy(TestOverwritePropClass::class, fn () => new TestOverwritePropClass('123', 5)); - - $this->assertSame('123', $proxy->getDep()); - $this->assertSame(1, $proxy->increment()); - } -} diff --git a/src/Symfony/Component/VarExporter/Tests/LegacyProxyHelperTest.php b/src/Symfony/Component/VarExporter/Tests/LegacyProxyHelperTest.php deleted file mode 100644 index 71c46c448ac1d..0000000000000 --- a/src/Symfony/Component/VarExporter/Tests/LegacyProxyHelperTest.php +++ /dev/null @@ -1,200 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\VarExporter\Tests; - -use Symfony\Component\VarExporter\Exception\LogicException; -use Symfony\Component\VarExporter\ProxyHelper; -use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Php82NullStandaloneReturnType; -use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\StringMagicGetClass; - -/** - * @requires PHP < 8.4 - * - * @group legacy - */ -class LegacyProxyHelperTest extends ProxyHelperTest -{ - public function testGenerateLazyProxy() - { - $expected = <<<'EOPHP' - extends \Symfony\Component\VarExporter\Tests\TestForProxyHelper implements \Symfony\Component\VarExporter\LazyObjectInterface - { - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; - - public function foo1(): ?\Symfony\Component\VarExporter\Tests\Bar - { - if (isset($this->lazyObjectState)) { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo1(...\func_get_args()); - } - - return parent::foo1(...\func_get_args()); - } - - public function foo4(\Symfony\Component\VarExporter\Tests\Bar|string $b, &$d): void - { - if (isset($this->lazyObjectState)) { - ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo4($b, $d, ...\array_slice(\func_get_args(), 2)); - } else { - parent::foo4($b, $d, ...\array_slice(\func_get_args(), 2)); - } - } - - protected function foo7() - { - if (isset($this->lazyObjectState)) { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo7(...\func_get_args()); - } - - return throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelper::foo7()".'); - } - } - - // 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); - - EOPHP; - - $this->assertSame($expected, ProxyHelper::generateLazyProxy(new \ReflectionClass(TestForProxyHelper::class))); - } - - public function testGenerateLazyProxyForInterfaces() - { - $expected = <<<'EOPHP' - implements \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface1, \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2, \Symfony\Component\VarExporter\LazyObjectInterface - { - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; - - public function initializeLazyObject(): \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface1&\Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2 - { - if ($state = $this->lazyObjectState ?? null) { - return $state->realInstance ??= ($state->initializer)(); - } - - return $this; - } - - public function foo1(): ?\Symfony\Component\VarExporter\Tests\Bar - { - if (isset($this->lazyObjectState)) { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo1(...\func_get_args()); - } - - return throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface1::foo1()".'); - } - - public function foo2(?\Symfony\Component\VarExporter\Tests\Bar $b, ...$d): \Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2 - { - if (isset($this->lazyObjectState)) { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo2(...\func_get_args()); - } - - return throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2::foo2()".'); - } - - public static function foo3(): string - { - throw new \BadMethodCallException('Cannot forward abstract method "Symfony\Component\VarExporter\Tests\TestForProxyHelperInterface2::foo3()".'); - } - } - - // 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); - - EOPHP; - - $this->assertSame($expected, ProxyHelper::generateLazyProxy(null, [new \ReflectionClass(TestForProxyHelperInterface1::class), new \ReflectionClass(TestForProxyHelperInterface2::class)])); - } - - public static function classWithUnserializeMagicMethodProvider(): iterable - { - yield 'not type hinted __unserialize method' => [new class { - public function __unserialize($array): void - { - } - }, <<<'EOPHP' - implements \Symfony\Component\VarExporter\LazyObjectInterface - { - use \Symfony\Component\VarExporter\LazyProxyTrait { - __unserialize as private __doUnserialize; - } - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; - - public function __unserialize($data): void - { - $this->__doUnserialize($data); - } - } - EOPHP]; - - yield 'type hinted __unserialize method' => [new class { - public function __unserialize(array $array): void - { - } - }, <<<'EOPHP' - implements \Symfony\Component\VarExporter\LazyObjectInterface - { - use \Symfony\Component\VarExporter\LazyProxyTrait; - - private const LAZY_OBJECT_PROPERTY_SCOPES = []; - } - EOPHP]; - } - - public function testAttributes() - { - $expected = <<<'EOPHP' - - public function foo(#[\SensitiveParameter] $a): int - { - if (isset($this->lazyObjectState)) { - return ($this->lazyObjectState->realInstance ??= ($this->lazyObjectState->initializer)())->foo(...\func_get_args()); - } - - return parent::foo(...\func_get_args()); - } - } - - EOPHP; - - $class = new \ReflectionClass(new class { - #[SomeAttribute] - public function foo(#[\SensitiveParameter, AnotherAttribute] $a): int - { - } - }); - - $this->assertStringContainsString($expected, ProxyHelper::generateLazyProxy($class)); - } - - public function testCannotGenerateGhostForStringMagicGet() - { - $this->expectException(LogicException::class); - ProxyHelper::generateLazyGhost(new \ReflectionClass(StringMagicGetClass::class)); - } - - public function testNullStandaloneReturnType() - { - self::assertStringContainsString( - 'public function foo(): null', - ProxyHelper::generateLazyProxy(new \ReflectionClass(Php82NullStandaloneReturnType::class)) - ); - } -} diff --git a/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php b/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php index ab396bc902ce6..0bf8cda8ba746 100644 --- a/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php +++ b/src/Symfony/Component/VarExporter/Tests/ProxyHelperTest.php @@ -16,9 +16,6 @@ use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Hooked; use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Php82NullStandaloneReturnType; -/** - * @requires PHP 8.4 - */ class ProxyHelperTest extends TestCase { /** @@ -282,9 +279,6 @@ public function testNullStandaloneReturnType() ); } - /** - * @requires PHP 8.4 - */ public function testPropertyHooks() { $proxyCode = ProxyHelper::generateLazyProxy(new \ReflectionClass(Hooked::class)); diff --git a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php index 6ca98b91487aa..855684e8aea44 100644 --- a/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php +++ b/src/Symfony/Component/VarExporter/Tests/VarExporterTest.php @@ -237,10 +237,6 @@ public static function provideExport() yield ['unit-enum', [FooUnitEnum::Bar], true]; yield ['readonly', new FooReadonly('k', 'v')]; - if (\PHP_VERSION_ID < 80400) { - return; - } - yield ['backed-property', new BackedProperty('name')]; }