1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Framework package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// ------------------------------------------------------------------------ |
13
|
|
|
|
14
|
|
|
namespace O2System\Framework\Http\Presenter\Repositories; |
15
|
|
|
|
16
|
|
|
// ------------------------------------------------------------------------ |
17
|
|
|
|
18
|
|
|
use O2System\Psr\Patterns\Structural\Repository\AbstractRepository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Widgets |
22
|
|
|
* |
23
|
|
|
* @package O2System\Framework\Http\Presenter\Repositories |
24
|
|
|
*/ |
25
|
|
|
class Widgets extends AbstractRepository |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Widgets::hasWidget |
29
|
|
|
* |
30
|
|
|
* @param string $widgetOffset |
31
|
|
|
* |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
public function hasWidget($widgetOffset) |
35
|
|
|
{ |
36
|
|
|
return $this->__isset($widgetOffset); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// ------------------------------------------------------------------------ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Widgets::load |
43
|
|
|
* |
44
|
|
|
* @param string $widgetOffset |
45
|
|
|
* |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
public function load($widgetOffset) |
49
|
|
|
{ |
50
|
|
|
$widgetDirectory = modules()->current()->getRealPath() . 'Widgets' . DIRECTORY_SEPARATOR . studlycase($widgetOffset) . DIRECTORY_SEPARATOR; |
|
|
|
|
51
|
|
|
|
52
|
|
|
if (is_dir($widgetDirectory)) { |
53
|
|
|
$widget = new DataStructures\Module\Widget($widgetDirectory); |
|
|
|
|
54
|
|
|
$this->store(camelcase($widgetOffset), $widget); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this->exists($widgetOffset); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
// ------------------------------------------------------------------------ |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Widgets::get |
64
|
|
|
* |
65
|
|
|
* @param string $offset |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function get($offset) |
70
|
|
|
{ |
71
|
|
|
if (null !== ($widget = parent::get($offset))) { |
72
|
|
|
|
73
|
|
|
$widgetViewFilePath = $widget->getRealPath() . 'Views' . DIRECTORY_SEPARATOR . $offset . '.phtml'; |
74
|
|
|
|
75
|
|
|
if (presenter()->theme->use === true) { |
|
|
|
|
76
|
|
|
$widgetViewReplacementPath = str_replace( |
77
|
|
|
$widget->getRealPath() . 'Views' . DIRECTORY_SEPARATOR, |
78
|
|
|
presenter()->theme->active->getPathName() . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, [ |
|
|
|
|
79
|
|
|
'views', |
80
|
|
|
'widgets', |
81
|
|
|
]) . DIRECTORY_SEPARATOR, |
82
|
|
|
$widgetViewFilePath |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
$viewsFileExtensions = [ |
86
|
|
|
'.php', |
87
|
|
|
'.phtml', |
88
|
|
|
]; |
89
|
|
|
|
90
|
|
|
// Add Theme File Extensions |
91
|
|
|
if (presenter()->theme->active->getPresets()->offsetExists('extension')) { |
92
|
|
|
array_unshift($viewsFileExtensions, |
93
|
|
|
presenter()->theme->active->getPresets()->offsetGet('extension')); |
94
|
|
|
} elseif (presenter()->theme->active->getPresets()->offsetExists('extensions')) { |
95
|
|
|
$viewsFileExtensions = array_merge( |
96
|
|
|
presenter()->theme->active->getPresets()->offsetGet('extensions'), |
97
|
|
|
$viewsFileExtensions |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
foreach ($viewsFileExtensions as $viewsFileExtension) { |
102
|
|
|
if (is_file($widgetViewReplacementPath . $viewsFileExtension)) { |
103
|
|
|
$widgetViewFilePath = $widgetViewReplacementPath . $viewsFileExtension; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
loader()->addNamespace($widget->getNamespace(), $widget->getRealPath()); |
110
|
|
|
$widgetPresenterClassName = $widgetPresenterClassName = $widget->getNamespace() . 'Presenters\\' . studlycase($offset); |
|
|
|
|
111
|
|
|
|
112
|
|
|
$widgetPresenter = new $widgetPresenterClassName(); |
113
|
|
|
|
114
|
|
|
if (is_file($widgetViewFilePath)) { |
115
|
|
|
parser()->loadVars($widgetPresenter->getArrayCopy()); |
116
|
|
|
parser()->loadFile($widgetViewFilePath); |
117
|
|
|
|
118
|
|
|
return parser()->parse(); |
119
|
|
|
} elseif (method_exists($widgetPresenter, 'render')) { |
120
|
|
|
return $widgetPresenter->render(); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
return null; |
125
|
|
|
} |
126
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.