|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @author: Abdul Qureshi. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file has been modified from the original source. |
|
7
|
|
|
* See original here: |
|
8
|
|
|
* |
|
9
|
|
|
* @link: https://github.com/progsmile/request-validator |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace TheSupportGroup\Common\Validator\Helpers; |
|
12
|
|
|
|
|
13
|
|
|
use TheSupportGroup\Common\ValidationInterop\ValidationProviderInterface; |
|
14
|
|
|
use TheSupportGroup\Common\Validator\Contracts\Helpers\RulesFactoryInterface; |
|
15
|
|
|
use TheSupportGroup\Common\Validator\Contracts\Helpers\ValidationFacadeInterface; |
|
16
|
|
|
use TheSupportGroup\Common\Validator\Contracts\Helpers\ValidationResultProcessorInterface; |
|
17
|
|
|
use TheSupportGroup\Common\Validator\Validator; |
|
18
|
|
|
|
|
19
|
|
|
class ValidatorFacade implements ValidationFacadeInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var ValidationProviderInterface $validationProvider |
|
23
|
|
|
*/ |
|
24
|
|
|
private $validationProvider; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ValidationResultProcessorInterface $validationResultProcessor |
|
28
|
|
|
*/ |
|
29
|
|
|
private $validationResultProcessor; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var RulesFactoryInterface $rulesFactory |
|
33
|
|
|
*/ |
|
34
|
|
|
private $rulesFactory; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param ValidationProviderInterface $validationProvider |
|
38
|
|
|
* @param ValidationResultProcessorInterface $validationResultProcessor |
|
39
|
|
|
* @param RulesFactoryInterface $rulesFactory |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct( |
|
42
|
|
|
ValidationProviderInterface $validationProvider, |
|
43
|
|
|
ValidationResultProcessorInterface $validationResultProcessor, |
|
44
|
|
|
RulesFactoryInterface $rulesFactory |
|
45
|
|
|
) { |
|
46
|
|
|
$this->validationProvider = $validationProvider; |
|
47
|
|
|
$this->validationResultProcessor = $validationResultProcessor; |
|
48
|
|
|
$this->rulesFactory = $rulesFactory; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param array $inputData |
|
53
|
|
|
* @param array $rules |
|
54
|
|
|
* @param array $errorMessages |
|
55
|
|
|
* |
|
56
|
|
|
* @return ValidationResultProcessor |
|
|
|
|
|
|
57
|
|
|
*/ |
|
58
|
|
|
public function validate( |
|
59
|
|
|
array $inputData, |
|
60
|
|
|
array $rules = [], |
|
61
|
|
|
array $errorMessages = [] |
|
62
|
|
|
) { |
|
63
|
|
|
return (new Validator( |
|
64
|
|
|
$this->validationProvider, |
|
65
|
|
|
$this->validationResultProcessor, |
|
66
|
|
|
$this->rulesFactory, |
|
67
|
|
|
$inputData, |
|
68
|
|
|
$rules, |
|
69
|
|
|
$errorMessages |
|
70
|
|
|
))->validate(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.