1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright 2018 Vladimir Jimenez |
5
|
|
|
* @license https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace allejo\stakx\MarkupEngine; |
9
|
|
|
|
10
|
|
|
use __; |
11
|
|
|
use allejo\stakx\Exception\UnsupportedMarkupException; |
12
|
|
|
|
13
|
|
|
class MarkupEngineManager |
14
|
|
|
{ |
15
|
|
|
private $enginesByTags = []; |
16
|
|
|
private $enginesByExtension = []; |
17
|
|
|
|
18
|
76 |
|
public function addMarkupEngines(/*iterable*/ $markupEngines) |
19
|
|
|
{ |
20
|
76 |
|
foreach ($markupEngines as $markupEngine) |
21
|
|
|
{ |
22
|
76 |
|
$this->addMarkupEngine($markupEngine); |
23
|
|
|
} |
24
|
76 |
|
} |
25
|
|
|
|
26
|
76 |
|
public function addMarkupEngine(MarkupEngineInterface $markupEngine) |
27
|
|
|
{ |
28
|
76 |
|
$extensions = $markupEngine->getExtensions(); |
29
|
76 |
|
$primaryExt = __::first($extensions); |
|
|
|
|
30
|
|
|
|
31
|
76 |
|
foreach ($extensions as $k => $extension) |
32
|
|
|
{ |
33
|
76 |
|
if ($k === 0) |
34
|
|
|
{ |
35
|
76 |
|
$this->enginesByExtension[$extension] = $markupEngine; |
36
|
|
|
} |
37
|
|
|
else |
38
|
|
|
{ |
39
|
76 |
|
$this->enginesByExtension[$extension] = &$this->enginesByExtension[$primaryExt]; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
76 |
|
$this->enginesByTags[$markupEngine->getTemplateTag()] = &$this->enginesByExtension[$primaryExt]; |
44
|
76 |
|
} |
45
|
|
|
|
46
|
|
|
public function getEngineByTag($tag) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
if (isset($this->enginesByTags[$tag])) |
49
|
|
|
{ |
50
|
|
|
return $this->enginesByTags[$tag]; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
throw new UnsupportedMarkupException($tag, 'There is no support to handle this markup format.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
64 |
|
public function getEngineByExtension($extension) |
|
|
|
|
57
|
|
|
{ |
58
|
64 |
|
if (isset($this->enginesByExtension[$extension])) |
59
|
|
|
{ |
60
|
64 |
|
return $this->enginesByExtension[$extension]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
throw new UnsupportedMarkupException($extension, 'There is no support to handle this markup format.'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getTemplateTags() |
67
|
|
|
{ |
68
|
|
|
return array_filter(array_keys($this->enginesByTags)); |
69
|
|
|
} |
70
|
|
|
|
71
|
36 |
|
public function getSupportedExtensions() |
72
|
|
|
{ |
73
|
36 |
|
return array_keys($this->enginesByExtension); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: