1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Synapse\Cmf\Framework\Engine; |
4
|
|
|
|
5
|
|
|
use Synapse\Cmf\Framework\Engine\Decorator\Component\HtmlDecorator as ComponentDecorator; |
6
|
|
|
use Synapse\Cmf\Framework\Engine\Decorator\Content\HtmlDecorator as ContentDecorator; |
7
|
|
|
use Synapse\Cmf\Framework\Engine\Decorator\Content\ImmutableDecorator; |
8
|
|
|
use Synapse\Cmf\Framework\Engine\Resolver\ThemeResolver; |
9
|
|
|
use Synapse\Cmf\Framework\Theme\Component\Model\ComponentInterface; |
10
|
|
|
use Synapse\Cmf\Framework\Theme\Content\Model\ContentInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Synapse engine main class, entry point of all other decorators. |
14
|
|
|
*/ |
15
|
|
|
class Engine |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var ThemeResolver |
19
|
|
|
*/ |
20
|
|
|
protected $themeResolver; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var ContentDecorator |
24
|
|
|
*/ |
25
|
|
|
protected $contentDecorator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var ComponentDecorator |
29
|
|
|
*/ |
30
|
|
|
protected $componentDecorator; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $currentThemeName; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Construct. |
39
|
|
|
* |
40
|
|
|
* @param ThemeResolver $themeResolver |
41
|
|
|
* @param ContentDecorator $contentDecorator |
42
|
|
|
* @param ComponentDecorator $componentDecorator |
43
|
|
|
*/ |
44
|
|
|
public function __construct( |
45
|
|
|
ThemeResolver $themeResolver, |
46
|
|
|
ContentDecorator $contentDecorator, |
47
|
|
|
ComponentDecorator $componentDecorator |
48
|
|
|
) { |
49
|
|
|
$this->themeResolver = $themeResolver; |
50
|
|
|
$this->contentDecorator = $contentDecorator; |
51
|
|
|
$this->componentDecorator = $componentDecorator; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Enable given theme name if he exists. |
56
|
|
|
* |
57
|
|
|
* @param string $themeName |
58
|
|
|
* |
59
|
|
|
* @return self |
60
|
|
|
*/ |
61
|
|
|
public function enableTheme($themeName) |
62
|
|
|
{ |
63
|
|
|
// Resolve theme right now to not have an unstable |
64
|
|
|
// context with an inexisting theme |
65
|
|
|
$this->currentTheme = $this->themeResolver->resolve( |
|
|
|
|
66
|
|
|
$themeName |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
return $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Enable default theme. |
74
|
|
|
* |
75
|
|
|
* @return self |
76
|
|
|
*/ |
77
|
|
|
public function enableDefaultTheme() |
78
|
|
|
{ |
79
|
|
|
$this->currentTheme = $this->themeResolver->resolve(null); |
|
|
|
|
80
|
|
|
|
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns current activated theme. |
86
|
|
|
* |
87
|
|
|
* @return ThemeInterface |
88
|
|
|
*/ |
89
|
|
|
public function getCurrentTheme() |
90
|
|
|
{ |
91
|
|
|
return $this->currentTheme; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create and return a DecoratorInterface for given content. |
96
|
|
|
* |
97
|
|
|
* @param ContentInterface|ComponentInterface $decorable |
98
|
|
|
* @param string $templateTypeName requested template type name to decorate decorable on |
99
|
|
|
* |
100
|
|
|
* @return Synapse\Cmf\Framework\Engine\Decorator\DecoratorInterface |
101
|
|
|
*/ |
102
|
|
|
public function createDecorator($decorable, $templateTypeName = null) |
103
|
|
|
{ |
104
|
|
|
// Main content rendering |
105
|
|
|
if ($decorable instanceof ContentInterface) { |
106
|
|
|
return new ImmutableDecorator( |
107
|
|
|
$decorable, |
108
|
|
|
$this->contentDecorator, |
109
|
|
|
$this->currentTheme ?: $this->themeResolver->resolve(), |
|
|
|
|
110
|
|
|
$templateTypeName |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Component rendering |
115
|
|
|
if ($decorable instanceof ComponentInterface) { |
116
|
|
|
return $this->componentDecorator; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
throw new \InvalidArgumentException(sprintf( |
120
|
|
|
'Given decorable "%s" is not supported by Synapse. Check your configuration.', |
121
|
|
|
is_object($decorable) ? get_class($decorable) : gettype($decorable) |
122
|
|
|
)); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.