| @@ 9-40 (lines=32) @@ | ||
| 6 | ||
| 7 | use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; |
|
| 8 | ||
| 9 | final class AndPolicy implements PolicyInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var array|PolicyInterface[] |
|
| 13 | */ |
|
| 14 | private $policies; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param array|PolicyInterface[] $policies |
|
| 18 | */ |
|
| 19 | public function __construct(array $policies) |
|
| 20 | { |
|
| 21 | $this->policies = $policies; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param NormalizerContextInterface $context |
|
| 26 | * @param object|mixed $object |
|
| 27 | * |
|
| 28 | * @return bool |
|
| 29 | */ |
|
| 30 | public function isCompliant(NormalizerContextInterface $context, $object): bool |
|
| 31 | { |
|
| 32 | foreach ($this->policies as $policy) { |
|
| 33 | if (false === $policy->isCompliant($context, $object)) { |
|
| 34 | return false; |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| 38 | return true; |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| @@ 9-40 (lines=32) @@ | ||
| 6 | ||
| 7 | use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface; |
|
| 8 | ||
| 9 | final class OrPolicy implements PolicyInterface |
|
| 10 | { |
|
| 11 | /** |
|
| 12 | * @var array|PolicyInterface[] |
|
| 13 | */ |
|
| 14 | private $policies; |
|
| 15 | ||
| 16 | /** |
|
| 17 | * @param array|PolicyInterface[] $policies |
|
| 18 | */ |
|
| 19 | public function __construct(array $policies) |
|
| 20 | { |
|
| 21 | $this->policies = $policies; |
|
| 22 | } |
|
| 23 | ||
| 24 | /** |
|
| 25 | * @param NormalizerContextInterface $context |
|
| 26 | * @param object|mixed $object |
|
| 27 | * |
|
| 28 | * @return bool |
|
| 29 | */ |
|
| 30 | public function isCompliant(NormalizerContextInterface $context, $object): bool |
|
| 31 | { |
|
| 32 | foreach ($this->policies as $policy) { |
|
| 33 | if (true === $policy->isCompliant($context, $object)) { |
|
| 34 | return true; |
|
| 35 | } |
|
| 36 | } |
|
| 37 | ||
| 38 | return false; |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||