-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathIntegrationModuleAccessValidator.php
More file actions
44 lines (38 loc) · 1.51 KB
/
IntegrationModuleAccessValidator.php
File metadata and controls
44 lines (38 loc) · 1.51 KB
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
<?php
namespace RetailCrm\DeliveryModuleBundle\Validator\Constraints;
use RetailCrm\DeliveryModuleBundle\Exception\AbstractModuleException;
use RetailCrm\DeliveryModuleBundle\Exception\ServerUnreachableException;
use RetailCrm\DeliveryModuleBundle\Service\ModuleManagerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class IntegrationModuleAccessValidator extends ConstraintValidator
{
/** @var ModuleManagerInterface */
private $moduleManager;
public function __construct(ModuleManagerInterface $moduleManager)
{
$this->moduleManager = $moduleManager;
}
public function validate($account, Constraint $constraint)
{
if (!($constraint instanceof IntegrationModuleAccess)) {
throw new UnexpectedTypeException($constraint, IntegrationModuleAccess::class);
}
try {
$this->moduleManager->checkAccess();
} catch (ServerUnreachableException $e) {
$this->context
->buildViolation('integration_module_access.server_unreachable_exception')
->atPath($constraint->path)
->addViolation()
;
} catch (AbstractModuleException $e) {
$this->context
->buildViolation('integration_module_access.module_access_exception')
->atPath($constraint->path)
->addViolation()
;
}
}
}