1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Serializer package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\Serializer\Exclusion; |
13
|
|
|
|
14
|
|
|
use Ivory\Serializer\Context\ContextInterface; |
15
|
|
|
use Ivory\Serializer\Mapping\ClassMetadataInterface; |
16
|
|
|
use Ivory\Serializer\Mapping\PropertyMetadataInterface; |
17
|
|
|
use Ivory\Serializer\Mapping\TypeMetadataInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ChainExclusionStrategy implements ExclusionStrategyInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ExclusionStrategyInterface[] |
26
|
|
|
*/ |
27
|
|
|
private $strategies = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ExclusionStrategyInterface[] $strategies |
31
|
|
|
*/ |
32
|
|
|
public function __construct(array $strategies) |
33
|
|
|
{ |
34
|
|
|
$this->strategies = $strategies; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function skipClass(ClassMetadataInterface $class, ContextInterface $context) |
41
|
|
|
{ |
42
|
|
|
foreach ($this->strategies as $strategy) { |
43
|
|
|
if ($strategy->skipClass($class, $context)) { |
44
|
|
|
return true; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return false; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function skipProperty(PropertyMetadataInterface $property, ContextInterface $context) |
55
|
|
|
{ |
56
|
|
|
foreach ($this->strategies as $strategy) { |
57
|
|
|
if ($strategy->skipProperty($property, $context)) { |
58
|
|
|
return true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function skipType(TypeMetadataInterface $type, ContextInterface $context) |
69
|
|
|
{ |
70
|
|
|
foreach ($this->strategies as $strategy) { |
71
|
|
|
if ($strategy->skipType($type, $context)) { |
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|