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; |
19
|
|
|
|
20
|
|
|
use ApaiIO\Configuration\ConfigurationInterface; |
21
|
|
|
use ApaiIO\Operations\OperationInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ApaiIO Core |
25
|
|
|
* Bundles all components |
26
|
|
|
* |
27
|
|
|
* http://www.amazon.com |
28
|
|
|
* |
29
|
|
|
* @author Jan Eichhorn <[email protected]> |
30
|
|
|
* |
31
|
|
|
* @see https://github.com/Exeu/apai-io/wiki Wiki |
32
|
|
|
* @see https://github.com/Exeu/apai-io Source |
33
|
|
|
*/ |
34
|
|
|
class ApaiIO |
35
|
|
|
{ |
36
|
|
|
const VERSION = "2.0.0-DEV"; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Configuration. |
40
|
|
|
* |
41
|
|
|
* @var ConfigurationInterface |
42
|
|
|
*/ |
43
|
|
|
protected $configuration; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param ConfigurationInterface $configuration |
47
|
|
|
*/ |
48
|
2 |
|
public function __construct(ConfigurationInterface $configuration = null) |
49
|
|
|
{ |
50
|
2 |
|
$this->configuration = $configuration; |
51
|
2 |
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param ConfigurationInterface $configuration |
55
|
|
|
*/ |
56
|
|
|
public function setConfiguration(ConfigurationInterface $configuration) |
57
|
|
|
{ |
58
|
|
|
$this->configuration = $configuration; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Runs the given operation. |
63
|
|
|
* |
64
|
|
|
* @param OperationInterface $operation The operationobject |
65
|
|
|
* |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
2 |
|
public function runOperation(OperationInterface $operation) |
69
|
|
|
{ |
70
|
2 |
|
$request = $this->configuration->getRequest(); |
71
|
|
|
|
72
|
2 |
|
$response = $request->perform($operation, $this->configuration); |
73
|
|
|
|
74
|
2 |
|
return $this->applyResponseTransformer($response); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Applies a responsetransformer. |
79
|
|
|
* |
80
|
|
|
* @param mixed $response The response of the request |
81
|
|
|
* |
82
|
|
|
* @return mixed |
83
|
|
|
*/ |
84
|
2 |
|
protected function applyResponseTransformer($response) |
85
|
|
|
{ |
86
|
2 |
|
if (null === $responseTransformer = $this->configuration->getResponseTransformer()) { |
87
|
1 |
|
return $response; |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
return $responseTransformer->transform($response); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|