diff --git a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php index 8e8952c7f4e23..d961dfdb4ac45 100644 --- a/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php +++ b/src/Symfony/Component/PropertyInfo/PropertyInfoExtractor.php @@ -90,6 +90,12 @@ public function isInitializable(string $class, string $property, array $context private function extract(iterable $extractors, string $method, array $arguments): mixed { foreach ($extractors as $extractor) { + if (!method_exists($extractor, $method)) { + trigger_deprecation('symfony/property-info', '7.1', 'Not implementing the "%s()" method in class "%s" is deprecated."', $method, $extractor::class); + + continue; + } + if (null !== $value = $extractor->{$method}(...$arguments)) { return $value; } diff --git a/src/Symfony/Component/PropertyInfo/Tests/AbstractPropertyInfoExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/AbstractPropertyInfoExtractorTest.php index 6f5c67131124e..ae07682eb0f5b 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/AbstractPropertyInfoExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/AbstractPropertyInfoExtractorTest.php @@ -19,6 +19,7 @@ use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyExtractor; +use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyLegacyExtractor; use Symfony\Component\PropertyInfo\Tests\Fixtures\NullExtractor; use Symfony\Component\PropertyInfo\Type as LegacyType; use Symfony\Component\TypeInfo\Type; @@ -57,7 +58,10 @@ public function testGetLongDescription() public function testGetType() { - $this->assertEquals(Type::int(), $this->propertyInfo->getType('Foo', 'bar', [])); + $extractors = [new NullExtractor(), new DummyLegacyExtractor(), new DummyExtractor()]; + $propertyInfo = new PropertyInfoExtractor($extractors, $extractors, $extractors, $extractors, $extractors); + + $this->assertEquals(Type::int(), $propertyInfo->getType('Foo', 'bar', [])); } /** diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyLegacyExtractor.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyLegacyExtractor.php new file mode 100644 index 0000000000000..67385c1f111fa --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/DummyLegacyExtractor.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyInfo\Tests\Fixtures; + +use Symfony\Component\PropertyInfo\Extractor\ConstructorArgumentTypeExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; +use Symfony\Component\PropertyInfo\Type as LegacyType; +use Symfony\Component\TypeInfo\Type; + +class DummyLegacyExtractor implements PropertyListExtractorInterface, PropertyDescriptionExtractorInterface, PropertyTypeExtractorInterface, PropertyAccessExtractorInterface, PropertyInitializableExtractorInterface, ConstructorArgumentTypeExtractorInterface +{ + public function getShortDescription($class, $property, array $context = []): ?string + { + return 'short'; + } + + public function getLongDescription($class, $property, array $context = []): ?string + { + return 'long'; + } + + public function getTypes($class, $property, array $context = []): ?array + { + return [new LegacyType(LegacyType::BUILTIN_TYPE_INT)]; + } + + public function getTypesFromConstructor(string $class, string $property): ?array + { + return [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)]; + } + + public function getTypeFromConstructor(string $class, string $property): ?Type + { + return Type::string(); + } + + public function isReadable($class, $property, array $context = []): ?bool + { + return true; + } + + public function isWritable($class, $property, array $context = []): ?bool + { + return true; + } + + public function getProperties($class, array $context = []): ?array + { + return ['a', 'b']; + } + + public function isInitializable(string $class, string $property, array $context = []): ?bool + { + return true; + } +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: