|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Mediadevs\Validator; |
|
4
|
|
|
|
|
5
|
|
|
use Mediadevs\Validator\Factories\FilterFactory; |
|
6
|
|
|
|
|
7
|
|
|
class Validator |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The validation results will be stored in here |
|
11
|
|
|
* @var array |
|
12
|
|
|
*/ |
|
13
|
|
|
private $results = array(); |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Validating all the values and applying all the assigned filters |
|
17
|
|
|
* |
|
18
|
|
|
* @param array $request |
|
19
|
|
|
* @param array $configuration |
|
20
|
|
|
* |
|
21
|
|
|
* @return array |
|
22
|
|
|
*/ |
|
23
|
|
|
public function validate(array $request, array $configuration = array()): array |
|
24
|
|
|
{ |
|
25
|
|
|
$factory = new FilterFactory(); |
|
26
|
|
|
$arguments = new Arguments(); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
// Parsing through all the fields |
|
29
|
|
|
foreach ($arguments->getArguments($configuration) as $config) { |
|
30
|
|
|
// Assigning the variables for the factory |
|
31
|
|
|
$filter = $config['filter']; |
|
32
|
|
|
$thresholds = $config['thresholds']; |
|
33
|
|
|
$field = $config['field']; |
|
34
|
|
|
|
|
35
|
|
|
// Making sure $values is an array |
|
36
|
|
|
$values = is_array($request[$field]) ? $request[$field] : array($request[$field]); |
|
37
|
|
|
|
|
38
|
|
|
// Getting the configuration for the filter |
|
39
|
|
|
$results = $factory->build($filter, $values, $thresholds); |
|
40
|
|
|
|
|
41
|
|
|
// Creating a validation config for the current operation |
|
42
|
|
|
$this->results[] = [ |
|
43
|
|
|
'valid' => (bool) $results, |
|
44
|
|
|
'field' => (string) $field, |
|
45
|
|
|
'filter' => (string) $filter, |
|
46
|
|
|
'values' => (array) $values, |
|
47
|
|
|
'thresholds' => (array) $thresholds, |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->results; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths