1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace JMS\Serializer\Exclusion;
use JMS\Serializer\Context;
use JMS\Serializer\Expression\ExpressionEvaluatorInterface;
use JMS\Serializer\Metadata\PropertyMetadata;
use JMS\Serializer\SerializationContext;
/**
* Exposes an exclusion strategy based on the Symfony's expression language.
* This is not a standard exclusion strategy and can not be used in user applications.
*
* @internal
*
* @author Asmir Mustafic <goetas@gmail.com>
*/
class ExpressionLanguageExclusionStrategy
{
/**
* @var ExpressionEvaluatorInterface
*/
private $expressionEvaluator;
public function __construct(ExpressionEvaluatorInterface $expressionEvaluator)
{
$this->expressionEvaluator = $expressionEvaluator;
}
/**
* {@inheritDoc}
*/
public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext)
{
if (null === $property->excludeIf) {
return false;
}
$variables = [
'context' => $navigatorContext,
'property_metadata' => $property,
];
if ($navigatorContext instanceof SerializationContext) {
$variables['object'] = $navigatorContext->getObject();
} else {
$variables['object'] = null;
}
return $this->expressionEvaluator->evaluate($property->excludeIf, $variables);
}
}