|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace JMS\Serializer\Selector; |
|
6
|
|
|
|
|
7
|
|
|
use JMS\Serializer\Context; |
|
8
|
|
|
use JMS\Serializer\DeserializationContext; |
|
9
|
|
|
use JMS\Serializer\Exception\LogicException; |
|
10
|
|
|
use JMS\Serializer\Exclusion\ExclusionStrategyInterface; |
|
11
|
|
|
use JMS\Serializer\Exclusion\ExpressionLanguageExclusionStrategy; |
|
12
|
|
|
use JMS\Serializer\Expression\ExpressionEvaluatorInterface; |
|
13
|
|
|
use JMS\Serializer\Metadata\ClassMetadata; |
|
14
|
|
|
use JMS\Serializer\Metadata\ExpressionPropertyMetadata; |
|
15
|
|
|
use JMS\Serializer\Metadata\PropertyMetadata; |
|
16
|
|
|
use JMS\Serializer\Metadata\StaticPropertyMetadata; |
|
17
|
|
|
use JMS\Serializer\SerializationContext; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Asmir Mustafic <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
final class DefaultPropertySelector implements PropertySelectorInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var ExpressionEvaluatorInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
private $evaluator; |
|
28
|
|
|
/** |
|
29
|
|
|
* @var ExclusionStrategyInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $exclusionStrategy; |
|
32
|
|
|
/** |
|
33
|
|
|
* @var ExpressionLanguageExclusionStrategy |
|
34
|
|
|
*/ |
|
35
|
|
|
private $expressionExclusionStrategy; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
38
|
|
|
ExclusionStrategyInterface $exclusionStrategy, |
|
39
|
|
|
ExpressionEvaluatorInterface $evaluator |
|
40
|
|
|
) { |
|
41
|
|
|
$this->exclusionStrategy = $exclusionStrategy; |
|
42
|
|
|
$this->evaluator = $evaluator; |
|
43
|
|
|
$this->expressionExclusionStrategy = new ExpressionLanguageExclusionStrategy($evaluator); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param ClassMetadata $metadata |
|
48
|
|
|
* @param Context $context |
|
49
|
|
|
* @return PropertyMetadata[] |
|
50
|
|
|
*/ |
|
51
|
|
|
public function select(ClassMetadata $metadata, Context $context): array |
|
52
|
|
|
{ |
|
53
|
|
|
$values = []; |
|
54
|
|
|
foreach ($metadata->propertyMetadata as $propertyMetadata) { |
|
55
|
|
|
if ($context instanceof DeserializationContext && $propertyMetadata->readOnly) { |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ($this->exclusionStrategy->shouldSkipProperty($propertyMetadata, $context) || $this->expressionExclusionStrategy->shouldSkipProperty($propertyMetadata, $context)) { |
|
60
|
|
|
continue; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$values[] = $propertyMetadata; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $values; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|