1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Schema Validator |
4
|
|
|
* |
5
|
|
|
* @author Vlad Shashkov <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2021, The Myaza Software |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace SchemaValidator\CollectionInfoExtractor; |
12
|
|
|
|
13
|
|
|
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface; |
14
|
|
|
|
15
|
|
|
final class CollectionInfoExtractor implements CollectionInfoExtractorInterface |
16
|
|
|
{ |
17
|
8 |
|
public function __construct( |
18
|
|
|
private PropertyInfoExtractorInterface $propertyInfoExtractor |
19
|
|
|
) { |
20
|
8 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @psalm-suppress DeprecatedMethod |
24
|
|
|
*/ |
25
|
8 |
|
public function getValueType(string $class, string $propertyName): ValueType |
26
|
|
|
{ |
27
|
8 |
|
$typesProperty = $this->propertyInfoExtractor->getTypes($class, $propertyName); |
28
|
|
|
|
29
|
8 |
|
if (null === $typesProperty) { |
30
|
1 |
|
return new ValueType(null, true); |
31
|
|
|
} |
32
|
|
|
|
33
|
7 |
|
foreach ($typesProperty as $type) { |
34
|
5 |
|
if (!$type->isCollection()) { |
35
|
5 |
|
continue; |
36
|
|
|
} |
37
|
|
|
|
38
|
5 |
|
if (method_exists($type, 'getCollectionValueTypes')) { |
39
|
2 |
|
$valueTypes = $type->getCollectionValueTypes(); |
40
|
|
|
|
41
|
2 |
|
if ([] === $valueTypes) { |
42
|
|
|
return new ValueType(null, true); |
43
|
|
|
} |
44
|
|
|
|
45
|
2 |
|
$valueType = $valueTypes[0]; |
46
|
|
|
|
47
|
2 |
|
return new ValueType( |
48
|
2 |
|
$valueType->getClassName() ?? $valueType->getBuiltinType(), |
49
|
2 |
|
null === $valueType->getClassName() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
3 |
|
if (!method_exists($type, 'getCollectionValueType')) { |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
3 |
|
$valueType = $type->getCollectionValueType(); |
|
|
|
|
58
|
|
|
|
59
|
3 |
|
if (null === $valueType) { |
60
|
1 |
|
return new ValueType(null, true); |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
return new ValueType( |
64
|
2 |
|
$valueType->getClassName() ?? $valueType->getBuiltinType(), |
65
|
2 |
|
null === $valueType->getClassName() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
return new ValueType(null, true); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.