1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Package.php |
5
|
|
|
* |
6
|
|
|
* Base class for the Jaxon packages. |
7
|
|
|
* |
8
|
|
|
* @package jaxon-core |
|
|
|
|
9
|
|
|
* @author Thierry Feuzeu <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License |
11
|
|
|
* @link https://github.com/jaxon-php/jaxon-core |
12
|
|
|
*/ |
|
|
|
|
13
|
|
|
|
14
|
|
|
namespace Jaxon\Plugin; |
15
|
|
|
|
16
|
|
|
use Jaxon\App\View\ViewRenderer; |
17
|
|
|
use Jaxon\Request\Factory\Factory; |
18
|
|
|
use Jaxon\Utils\Config\Config; |
19
|
|
|
|
20
|
|
|
abstract class Package implements CodeGeneratorInterface |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The configuration options of the package |
24
|
|
|
* |
25
|
|
|
* @var Config |
26
|
|
|
*/ |
27
|
|
|
protected $xPkgConfig; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The request factory |
31
|
|
|
* |
32
|
|
|
* @var Factory |
33
|
|
|
*/ |
34
|
|
|
protected $xFactory; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* The view renderer |
38
|
|
|
* |
39
|
|
|
* @var ViewRenderer |
40
|
|
|
*/ |
41
|
|
|
protected $xRenderer; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Whether to include the getReadyScript() in the generated code. |
45
|
|
|
* |
46
|
|
|
* @var bool |
|
|
|
|
47
|
|
|
*/ |
48
|
|
|
protected $bReadyEnabled = false; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the path to the config file, or the config options in an array. |
52
|
|
|
* |
53
|
|
|
* @return string|array |
54
|
|
|
*/ |
55
|
|
|
abstract public static function config(); |
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the package config object |
59
|
|
|
* |
60
|
|
|
* @return Config |
61
|
|
|
*/ |
62
|
|
|
public function getConfig() |
63
|
|
|
{ |
64
|
|
|
return $this->xPkgConfig; |
65
|
|
|
} |
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param Config $xPkgConfig |
|
|
|
|
69
|
|
|
* @param Factory $xFactory |
|
|
|
|
70
|
|
|
* @param ViewRenderer $xRenderer |
|
|
|
|
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
*/ |
74
|
|
|
protected function _init(Config $xPkgConfig, Factory $xFactory, ViewRenderer $xRenderer) |
75
|
|
|
{ |
76
|
|
|
$this->xPkgConfig = $xPkgConfig; |
77
|
|
|
$this->xFactory = $xFactory; |
|
|
|
|
78
|
|
|
$this->xRenderer = $xRenderer; |
79
|
|
|
} |
|
|
|
|
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* This method is automatically called after the package instance is created and configured. |
83
|
|
|
* |
84
|
|
|
* @return void |
85
|
|
|
*/ |
86
|
|
|
public function init() |
87
|
|
|
{} |
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get the value of a given package option |
91
|
|
|
* |
92
|
|
|
* @param string $sOption The option name |
|
|
|
|
93
|
|
|
* @param mixed $xDefault The default value |
|
|
|
|
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function getOption(string $sOption, $xDefault = null) |
98
|
|
|
{ |
99
|
|
|
return $this->xPkgConfig->getOption($sOption, $xDefault); |
100
|
|
|
} |
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Get the request factory |
104
|
|
|
* |
105
|
|
|
* @return Factory |
106
|
|
|
*/ |
107
|
|
|
public function factory(): Factory |
108
|
|
|
{ |
109
|
|
|
return $this->xFactory; |
110
|
|
|
} |
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Get the view renderer |
114
|
|
|
* |
115
|
|
|
* @return ViewRenderer |
116
|
|
|
*/ |
117
|
|
|
public function view(): ViewRenderer |
118
|
|
|
{ |
119
|
|
|
return $this->xRenderer; |
120
|
|
|
} |
|
|
|
|
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Include the getReadyScript() in the generated code. |
124
|
|
|
* |
125
|
|
|
* @return void |
126
|
|
|
*/ |
127
|
|
|
public function ready() |
128
|
|
|
{ |
129
|
|
|
$this->bReadyEnabled = true; |
130
|
|
|
} |
|
|
|
|
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @inheritDoc |
134
|
|
|
*/ |
|
|
|
|
135
|
|
|
public function readyEnabled(): bool |
136
|
|
|
{ |
137
|
|
|
return $this->bReadyEnabled; |
138
|
|
|
} |
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @inheritDoc |
142
|
|
|
*/ |
|
|
|
|
143
|
|
|
public final function readyInlined(): bool |
144
|
|
|
{ |
145
|
|
|
// For packages, the getReadyScript() is never exported to external files. |
146
|
|
|
return true; |
147
|
|
|
} |
|
|
|
|
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @inheritDoc |
151
|
|
|
*/ |
|
|
|
|
152
|
|
|
public final function getHash(): string |
153
|
|
|
{ |
154
|
|
|
// Packages do not generate hash on their own. So we make this method final. |
155
|
|
|
return ''; |
156
|
|
|
} |
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @inheritDoc |
160
|
|
|
*/ |
|
|
|
|
161
|
|
|
public function getCss(): string |
162
|
|
|
{ |
163
|
|
|
return ''; |
164
|
|
|
} |
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @inheritDoc |
168
|
|
|
*/ |
|
|
|
|
169
|
|
|
public function getJs(): string |
170
|
|
|
{ |
171
|
|
|
return ''; |
172
|
|
|
} |
|
|
|
|
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @inheritDoc |
176
|
|
|
*/ |
|
|
|
|
177
|
|
|
public function getScript(): string |
178
|
|
|
{ |
179
|
|
|
return ''; |
180
|
|
|
} |
|
|
|
|
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @inheritDoc |
184
|
|
|
*/ |
|
|
|
|
185
|
|
|
public function getReadyScript(): string |
186
|
|
|
{ |
187
|
|
|
return ''; |
188
|
|
|
} |
|
|
|
|
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get the HTML code of the package home page |
192
|
|
|
* |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
abstract public function getHtml(): string; |
|
|
|
|
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Get the HTML code of the package home page |
199
|
|
|
* |
200
|
|
|
* This method is an alias for getHtml(). |
201
|
|
|
* |
202
|
|
|
* @return string |
203
|
|
|
*/ |
204
|
|
|
public function html(): string |
205
|
|
|
{ |
206
|
|
|
return $this->getHtml(); |
207
|
|
|
} |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|