1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* constraint event |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\JsonSchemaBundle\Validator\Constraint\Event; |
7
|
|
|
|
8
|
|
|
use JsonSchema\Constraints\Factory; |
9
|
|
|
use Symfony\Contracts\EventDispatcher\Event; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
13
|
|
|
* @license https://opensource.org/licenses/MIT MIT License |
14
|
|
|
* @link http://swisscom.ch |
15
|
|
|
*/ |
16
|
|
|
class ConstraintEvent extends Event |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
const NAME = 'graviton.json_schema.constraint'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var Factory |
25
|
|
|
*/ |
26
|
|
|
private $factory; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var mixed |
30
|
|
|
*/ |
31
|
|
|
private $element; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var mixed |
35
|
|
|
*/ |
36
|
|
|
private $schema; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
private $path; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
private $errors = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* ConstraintEvent constructor. |
50
|
|
|
* |
51
|
|
|
* @param Factory $factory factory |
52
|
|
|
* @param mixed $element element |
53
|
|
|
* @param mixed $schema schema |
54
|
|
|
* @param string $path path |
55
|
|
|
*/ |
56
|
|
|
public function __construct(Factory $factory, $element, $schema, $path) |
57
|
|
|
{ |
58
|
|
|
$this->factory = $factory; |
59
|
|
|
$this->element = $element; |
60
|
|
|
$this->schema = $schema; |
61
|
|
|
$this->path = $path; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return Factory |
66
|
|
|
*/ |
67
|
|
|
public function getFactory() |
68
|
|
|
{ |
69
|
|
|
return $this->factory; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return mixed |
74
|
|
|
*/ |
75
|
|
|
public function getElement() |
76
|
|
|
{ |
77
|
|
|
return $this->element; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return mixed |
82
|
|
|
*/ |
83
|
|
|
public function getSchema() |
84
|
|
|
{ |
85
|
|
|
return $this->schema; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getPath() |
92
|
|
|
{ |
93
|
|
|
return $this->path; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getErrors() |
100
|
|
|
{ |
101
|
|
|
return $this->errors; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* add an error message |
106
|
|
|
* |
107
|
|
|
* @param string $errorMessage message |
108
|
|
|
* @param string $propertyPath property path |
109
|
|
|
* @param string $constraint constraint |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function addError($errorMessage, $propertyPath = null, $constraint = '') |
114
|
|
|
{ |
115
|
|
|
$this->errors[] = [ |
116
|
|
|
'property' => (is_null($propertyPath) ? $this->getPath() : $propertyPath), |
117
|
|
|
'message' => $errorMessage, |
118
|
|
|
'constraint' => $constraint |
119
|
|
|
]; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|