-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBatchServiceDefinitionValidator.php
41 lines (34 loc) · 1.53 KB
/
BatchServiceDefinitionValidator.php
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
<?php
namespace Matthias\SymfonyServiceDefinitionValidator;
use Matthias\SymfonyServiceDefinitionValidator\Error\ValidationErrorFactoryInterface;
use Matthias\SymfonyServiceDefinitionValidator\Exception\DefinitionValidationExceptionInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class BatchServiceDefinitionValidator implements BatchServiceDefinitionValidatorInterface
{
private $serviceDefinitionValidator;
private $validationErrorFactory;
public function __construct(
ServiceDefinitionValidatorInterface $serviceDefinitionValidator,
ValidationErrorFactoryInterface $validationErrorFactory
) {
$this->serviceDefinitionValidator = $serviceDefinitionValidator;
$this->validationErrorFactory = $validationErrorFactory;
}
public function validate(array $serviceDefinitions)
{
$validationErrorList = $this->validationErrorFactory->createValidationErrorList();
foreach ($serviceDefinitions as $serviceId => $definition) {
try {
$this->serviceDefinitionValidator->validate($definition);
} catch (\Exception $exception) {
if ($exception instanceof DefinitionValidationExceptionInterface) {
$error = $this->validationErrorFactory->createValidationError($serviceId, $definition, $exception);
$validationErrorList->add($error);
} else {
throw $exception;
}
}
}
return $validationErrorList;
}
}