1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AmaTeam\ElasticSearch\Indexing; |
4
|
|
|
|
5
|
|
|
use AmaTeam\ElasticSearch\API\Indexing\Validation\ContextInterface; |
6
|
|
|
use AmaTeam\ElasticSearch\API\Indexing\ValidatorInterface; |
7
|
|
|
use AmaTeam\ElasticSearch\API\IndexingInterface; |
8
|
|
|
use AmaTeam\ElasticSearch\Indexing\Option\Infrastructure\Registry; |
9
|
|
|
use AmaTeam\ElasticSearch\Indexing\Validation\Constraint\ValidOptionName; |
10
|
|
|
use Symfony\Component\Validator\Constraints\NotNull; |
11
|
|
|
use Symfony\Component\Validator\ConstraintViolationListInterface; |
12
|
|
|
use Symfony\Component\Validator\Validation; |
13
|
|
|
|
14
|
|
|
class Validator implements ValidatorInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Registry |
18
|
|
|
*/ |
19
|
|
|
private $registry; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param Registry $registry |
23
|
|
|
*/ |
24
|
|
|
public function __construct(Registry $registry = null) |
25
|
|
|
{ |
26
|
|
|
$this->registry = $registry ?? Registry::getInstance(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function validate( |
30
|
|
|
IndexingInterface $indexing, |
31
|
|
|
ContextInterface $context = null |
32
|
|
|
): ConstraintViolationListInterface { |
33
|
|
|
$validator = Validation::createValidator()->startContext(); |
34
|
|
|
foreach ($indexing->getOptions() as $name => $value) { |
35
|
|
|
$validator->atPath($name); |
36
|
|
|
$option = $this->registry->find($name); |
37
|
|
|
if (!$option && $context->shouldPreserveUnknownOptions()) { |
|
|
|
|
38
|
|
|
continue; |
39
|
|
|
} |
40
|
|
|
$validator->validate($name, [new ValidOptionName()]); |
41
|
|
|
if (!$option) { |
42
|
|
|
continue; |
43
|
|
|
} |
44
|
|
|
$constraints = $option->getConstraints(); |
45
|
|
|
if ($option->allowsNullValue()) { |
46
|
|
|
$constraints[] = new NotNull(); |
47
|
|
|
} |
48
|
|
|
$validator->validate($value, $constraints); |
49
|
|
|
} |
50
|
|
|
return $validator->getViolations(); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.