1
|
|
|
<?php |
2
|
|
|
namespace Yoanm\JsonRpcServer\Domain\Event\Action; |
3
|
|
|
|
4
|
|
|
use Yoanm\JsonRpcServer\Domain\Event\JsonRpcServerEvent; |
5
|
|
|
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ValidateParamsEvent |
9
|
|
|
* |
10
|
|
|
* Dispatched before JSON-RPC will be called, in order to validate params |
11
|
|
|
*/ |
12
|
|
|
class ValidateParamsEvent implements JsonRpcServerEvent |
13
|
|
|
{ |
14
|
|
|
const EVENT_NAME = 'json_rpc_server_skd.validate_params'; |
15
|
|
|
|
16
|
|
|
/** @var JsonRpcMethodInterface */ |
17
|
|
|
private $method; |
18
|
|
|
/** @var array */ |
19
|
|
|
private $paramList = []; |
20
|
|
|
/** @var mixed[] */ |
21
|
|
|
private $violationList = []; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param JsonRpcMethodInterface $method |
25
|
|
|
* @param array $paramList |
26
|
|
|
*/ |
27
|
|
|
public function __construct(JsonRpcMethodInterface $method, array $paramList) |
28
|
|
|
{ |
29
|
|
|
$this->method = $method; |
30
|
|
|
$this->paramList = $paramList; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return JsonRpcMethodInterface |
35
|
|
|
*/ |
36
|
|
|
public function getMethod() : JsonRpcMethodInterface |
37
|
|
|
{ |
38
|
|
|
return $this->method; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getParamList() : array |
45
|
|
|
{ |
46
|
|
|
return $this->paramList; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param array $violationList |
51
|
|
|
* |
52
|
|
|
* @return ValidateParamsEvent |
53
|
|
|
*/ |
54
|
|
|
public function setViolationList(array $violationList) : ValidateParamsEvent |
55
|
|
|
{ |
56
|
|
|
$this->violationList = $violationList; |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param mixed $violation |
63
|
|
|
* |
64
|
|
|
* @return ValidateParamsEvent |
65
|
|
|
*/ |
66
|
|
|
public function addViolation($violation) : ValidateParamsEvent |
67
|
|
|
{ |
68
|
|
|
$this->violationList[] = $violation; |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public function getViolationList() : array |
77
|
|
|
{ |
78
|
|
|
return $this->violationList; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|