1 | <?php |
||
7 | abstract class MethodPluginBase implements MethodPluginInterface { |
||
8 | |||
9 | /** |
||
10 | * The method name. |
||
11 | */ |
||
12 | const METHOD = 'BASE'; |
||
13 | |||
14 | /** |
||
15 | * The parameters. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $parameters; |
||
20 | |||
21 | /** |
||
22 | * The API Key. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $apiKey; |
||
27 | |||
28 | /** |
||
29 | * The API Version. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $apiVersion; |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 25 | public function getMethod() { |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 25 | public function setParameters(array $parameters = array()) { |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 13 | public function getDefaultParameters() { |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 25 | public function getParameters() { |
|
62 | 25 | $defaultParameters = $this->getDefaultParameters(); |
|
63 | |||
64 | 25 | $params = []; |
|
65 | 25 | foreach ($this->getDefaultParameters() as $key => $parameter) { |
|
66 | 25 | if (in_array($this->getApiVersion(), (array) $defaultParameters[$key]['api'])) { |
|
67 | 25 | if (!is_null($parameter['value'])) { |
|
68 | 4 | $params[$key] = $parameter['value']; |
|
69 | 4 | } |
|
70 | 25 | } |
|
71 | 25 | } |
|
72 | |||
73 | 25 | foreach ((array) $this->parameters as $key => $value) { |
|
74 | 25 | if (array_key_exists($key, $defaultParameters)) { |
|
75 | 25 | if (in_array($this->getApiVersion(), (array) $defaultParameters[$key]['api'])) { |
|
76 | 25 | $params[$key] = $value; |
|
77 | 25 | } |
|
78 | 25 | } |
|
79 | 25 | } |
|
80 | |||
81 | 25 | $this->setParameters($params); |
|
82 | |||
83 | 25 | return array_filter([ |
|
84 | 25 | 'jsonrpc' => '2.0', |
|
85 | 25 | 'id' => $this->getRandomId(), |
|
86 | 25 | 'method' => $this->getMethod(), |
|
87 | 25 | 'params' => $params, |
|
88 | 25 | ]); |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Get a random ID. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 13 | public function getRandomId() { |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 13 | public function setApiVersion($apiVersion) { |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 13 | public function getApiVersion() { |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 13 | public function get(ResponseInterface $response, $key = NULL) { |
|
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 13 | public function getContent(ResponseInterface $response) { |
|
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getHeader(ResponseInterface $response, $name) { |
||
156 | |||
157 | } |
||
158 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: