|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of user_management |
|
4
|
|
|
* User: Sinan TURGUT <[email protected]> |
|
5
|
|
|
* Date: 24.06.2019 |
|
6
|
|
|
* php version 7.2 |
|
7
|
|
|
* |
|
8
|
|
|
* @category Assessment |
|
9
|
|
|
* @package UserManagement |
|
10
|
|
|
* @author Sinan TURGUT <[email protected]> |
|
11
|
|
|
* @license See LICENSE file |
|
12
|
|
|
* @link https://dev.sinanturgut.com.tr |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace UserManagement\Validation; |
|
16
|
|
|
|
|
17
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
|
|
|
|
|
18
|
|
|
use Respect\Validation\Exceptions\NestedValidationException; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Class Validator |
|
22
|
|
|
* @package UserManagement\Validation |
|
23
|
|
|
*/ |
|
24
|
|
|
class Validator |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $errors = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param ServerRequestInterface $request |
|
34
|
|
|
* @param array $rules |
|
35
|
|
|
* @return $this |
|
36
|
|
|
*/ |
|
37
|
|
|
public function validate(ServerRequestInterface $request, array $rules) |
|
38
|
|
|
{ |
|
39
|
|
|
foreach ($rules as $field => $rule) { |
|
40
|
|
|
try { |
|
41
|
|
|
$rule->setName($field)->assert($request->getParam($field)); |
|
42
|
|
|
} catch (NestedValidationException $e) { |
|
43
|
|
|
$this->errors[$field] = $e->getMessages(); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
$_SESSION['errors'] = $this->errors; |
|
47
|
|
|
return $this; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param array $values |
|
52
|
|
|
* @param array $rules |
|
53
|
|
|
* @return $this |
|
54
|
|
|
*/ |
|
55
|
|
|
public function validateArray(array $values, array $rules) |
|
56
|
|
|
{ |
|
57
|
|
|
foreach ($rules as $field => $rule) { |
|
58
|
|
|
try { |
|
59
|
|
|
$rule->setName($field)->assert($this->getValue($values, $field)); |
|
|
|
|
|
|
60
|
|
|
} catch (NestedValidationException $e) { |
|
61
|
|
|
$this->errors[$field] = $e->getMessages(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
$_SESSION['errors'] = $this->errors; |
|
65
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return bool |
|
72
|
|
|
*/ |
|
73
|
|
|
public function failed() |
|
74
|
|
|
{ |
|
75
|
|
|
return ! empty($this->errors); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return array |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getErrors() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->errors; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param $values |
|
88
|
|
|
* @param $field |
|
89
|
|
|
* @return null |
|
90
|
|
|
*/ |
|
91
|
|
|
private function getValue($values, $field) |
|
92
|
|
|
{ |
|
93
|
|
|
return isset($values[$field]) ? $values[$field] : null; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
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