1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2016 Jan Eichhorn <[email protected]> |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not use this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace ApaiIO\Operations; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A base implementation of the OperationInterface |
22
|
|
|
* |
23
|
|
|
* @author Jan Eichhorn <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractOperation implements OperationInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $parameters = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Returns an array of responseGroups |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
1 |
|
public function getResponseGroup() |
38
|
|
|
{ |
39
|
1 |
|
return $this->getSingleOperationParameter('ResponseGroup'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
1 |
|
public function setResponseGroup(array $responseGroup) |
46
|
|
|
{ |
47
|
1 |
|
$this->parameters['ResponseGroup'] = $responseGroup; |
48
|
|
|
|
49
|
1 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
11 |
|
public function getOperationParameter() |
56
|
|
|
{ |
57
|
11 |
|
return $this->parameters; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a single operation parameter if set |
62
|
|
|
* |
63
|
|
|
* @param string $keyName |
64
|
|
|
* |
65
|
|
|
* @return mixed|null |
66
|
|
|
*/ |
67
|
29 |
|
public function getSingleOperationParameter($keyName) |
68
|
|
|
{ |
69
|
29 |
|
return isset($this->parameters[$keyName]) ? $this->parameters[$keyName] : null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Magic setter and getter functions |
74
|
|
|
* |
75
|
|
|
* @param string $method Methodname |
76
|
|
|
* @param string $parameter Parameters |
77
|
|
|
* |
78
|
|
|
* @return \ApaiIO\Operations\AbstractOperation |
79
|
|
|
*/ |
80
|
5 |
|
public function __call($method, $parameter) |
81
|
|
|
{ |
82
|
5 |
|
if (substr($method, 0, 3) === 'set') { |
83
|
3 |
|
$this->parameters[substr($method, 3)] = array_shift($parameter); |
84
|
|
|
|
85
|
3 |
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
3 |
|
if (substr($method, 0, 3) === 'get') { |
89
|
2 |
|
$key = substr($method, 3); |
90
|
|
|
|
91
|
2 |
|
return isset($this->parameters[$key]) ? $this->parameters[$key] : null; |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
throw new \BadFunctionCallException(sprintf('The function "%s" does not exist!', $method)); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|