| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\PropertyInfo; |
| 13 |
|
| 14 |
use Symfony\Component\PropertyInfo\Util\LegacyTypeConverter; |
| 15 |
use Symfony\Component\TypeInfo\Type; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
> |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
class PropertyInfoExtractor implements PropertyInfoExtractorInterface, PropertyInitializableExtractorInterface |
| 25 |
{ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function __construct( |
| 34 |
private readonly iterable $listExtractors = [], |
| 35 |
private readonly iterable $typeExtractors = [], |
| 36 |
private readonly iterable $descriptionExtractors = [], |
| 37 |
private readonly iterable $accessExtractors = [], |
| 38 |
private readonly iterable $initializableExtractors = [], |
| 39 |
) { |
| 40 |
} |
| 41 |
|
| 42 |
public function getProperties(string $class, array $context = []): ?array |
| 43 |
{ |
| 44 |
return $this->extract($this->listExtractors, 'getProperties', [$class, $context]); |
| 45 |
} |
| 46 |
|
| 47 |
public function getShortDescription(string $class, string $property, array $context = []): ?string |
| 48 |
{ |
| 49 |
return $this->extract($this->descriptionExtractors, 'getShortDescription', [$class, $property, $context]); |
| 50 |
} |
| 51 |
|
| 52 |
public function getLongDescription(string $class, string $property, array $context = []): ?string |
| 53 |
{ |
| 54 |
return $this->extract($this->descriptionExtractors, 'getLongDescription', [$class, $property, $context]); |
| 55 |
} |
| 56 |
|
| 57 |
public function getType(string $class, string $property, array $context = []): ?Type |
| 58 |
{ |
| 59 |
foreach ($this->typeExtractors as $extractor) { |
| 60 |
if (!method_exists($extractor, 'getType')) { |
| 61 |
$legacyTypes = $extractor->getTypes($class, $property, $context); |
| 62 |
|
| 63 |
if (null !== $legacyTypes) { |
| 64 |
return LegacyTypeConverter::toTypeInfoType($legacyTypes); |
| 65 |
} |
| 66 |
|
| 67 |
continue; |
| 68 |
} |
| 69 |
|
| 70 |
if (null !== $value = $extractor->getType($class, $property, $context)) { |
| 71 |
return $value; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return null; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function getTypes(string $class, string $property, array $context = []): ?array |
| 82 |
{ |
| 83 |
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class); |
| 84 |
|
| 85 |
return $this->extract($this->typeExtractors, 'getTypes', [$class, $property, $context]); |
| 86 |
} |
| 87 |
|
| 88 |
public function isReadable(string $class, string $property, array $context = []): ?bool |
| 89 |
{ |
| 90 |
return $this->extract($this->accessExtractors, 'isReadable', [$class, $property, $context]); |
| 91 |
} |
| 92 |
|
| 93 |
public function isWritable(string $class, string $property, array $context = []): ?bool |
| 94 |
{ |
| 95 |
return $this->extract($this->accessExtractors, 'isWritable', [$class, $property, $context]); |
| 96 |
} |
| 97 |
|
| 98 |
public function isInitializable(string $class, string $property, array $context = []): ?bool |
| 99 |
{ |
| 100 |
return $this->extract($this->initializableExtractors, 'isInitializable', [$class, $property, $context]); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
private function extract(iterable $extractors, string $method, array $arguments): mixed |
| 110 |
{ |
| 111 |
foreach ($extractors as $extractor) { |
| 112 |
if (null !== $value = $extractor->{$method}(...$arguments)) { |
| 113 |
return $value; |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
return null; |
| 118 |
} |
| 119 |
} |