1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Starkerxp\CampaignBundle\Render; |
4
|
|
|
|
5
|
|
|
use Starkerxp\CampaignBundle\Render\Exception\ApiNotDefinedException; |
6
|
|
|
use Starkerxp\CampaignBundle\Render\Exception\VersionNotDefinedException; |
7
|
|
|
|
8
|
|
|
class RenderManager extends AbstractRender |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
private $renderService = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
private $api; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $version; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @throws ApiNotDefinedException |
27
|
|
|
* @throws VersionNotDefinedException |
28
|
|
|
* |
29
|
|
|
* @return string |
30
|
|
|
*/ |
31
|
|
|
public function render() |
32
|
|
|
{ |
33
|
|
|
if (!isset($this->api)) { |
34
|
|
|
throw new ApiNotDefinedException(); |
35
|
|
|
} |
36
|
|
|
if (!isset($this->version)) { |
37
|
|
|
throw new VersionNotDefinedException(); |
38
|
|
|
} |
39
|
|
|
$content = $this->getContenu(); |
40
|
|
|
$listesApi = array_unique(array_merge([], !is_array($this->api) ? [$this->api] : $this->api)); |
41
|
|
|
foreach ($listesApi as $api) { |
42
|
|
|
if ($renderService = $this->getSupport($api, $this->version)) { |
|
|
|
|
43
|
|
|
$renderService->setData($this->getData()); |
44
|
|
|
$renderService->setContenu($content); |
45
|
|
|
$content = $renderService->render(); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $content; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $api |
54
|
|
|
* @param string $version |
55
|
|
|
*/ |
56
|
|
|
public function getSupport($api, $version) |
57
|
|
|
{ |
58
|
|
|
foreach ($this->renderService as $service) { |
59
|
|
|
if ($service instanceof RenderInterface && $service->getSupport($api, $version)) { |
60
|
|
|
return $service; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param RenderInterface $service |
67
|
|
|
* |
68
|
|
|
* @return $this |
69
|
|
|
*/ |
70
|
|
|
public function addRenderService(RenderInterface $service) |
71
|
|
|
{ |
72
|
|
|
$this->renderService[] = $service; |
73
|
|
|
|
74
|
|
|
return $this; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function getRenderService() |
81
|
|
|
{ |
82
|
|
|
return $this->renderService; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getApi() |
89
|
|
|
{ |
90
|
|
|
return $this->api; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param string $api |
95
|
|
|
* |
96
|
|
|
* @return RenderManager |
97
|
|
|
*/ |
98
|
|
|
public function setApi($api) |
99
|
|
|
{ |
100
|
|
|
$this->api = strtolower($api); |
101
|
|
|
|
102
|
|
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getVersion() |
109
|
|
|
{ |
110
|
|
|
return $this->version; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $version |
115
|
|
|
* |
116
|
|
|
* @return RenderManager |
117
|
|
|
*/ |
118
|
|
|
public function setVersion($version) |
119
|
|
|
{ |
120
|
|
|
$this->version = strtolower($version); |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
} |
|
|
|
|
125
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.