1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System PHP 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
|
|
|
if ( ! function_exists('o2system')) { |
14
|
|
|
/** |
15
|
|
|
* o2system |
16
|
|
|
* |
17
|
|
|
* Convenient shortcut for O2System Framework Instance |
18
|
|
|
* |
19
|
|
|
* @return O2System\Framework |
20
|
|
|
*/ |
21
|
|
|
function o2system() |
22
|
|
|
{ |
23
|
|
|
return O2System\Framework::getInstance(); |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// ------------------------------------------------------------------------ |
28
|
|
|
|
29
|
|
|
if ( ! function_exists('loader')) { |
30
|
|
|
/** |
31
|
|
|
* loader |
32
|
|
|
* |
33
|
|
|
* Convenient shortcut for O2System Framework Loader service. |
34
|
|
|
* |
35
|
|
|
* @return O2System\Framework\Services\Loader |
36
|
|
|
*/ |
37
|
|
|
function loader() |
38
|
|
|
{ |
39
|
|
|
return services('loader'); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// ------------------------------------------------------------------------ |
44
|
|
|
|
45
|
|
|
if ( ! function_exists('config')) { |
46
|
|
|
/** |
47
|
|
|
* config |
48
|
|
|
* |
49
|
|
|
* Convenient shortcut for O2System Framework Config service. |
50
|
|
|
* |
51
|
|
|
* @return O2System\Framework\Services\Config|\O2System\Kernel\Datastructures\Config |
52
|
|
|
*/ |
53
|
|
|
function config() |
54
|
|
|
{ |
55
|
|
|
$args = func_get_args(); |
56
|
|
|
|
57
|
|
|
if ($countArgs = count($args)) { |
58
|
|
|
if(services()->has('config')) { |
|
|
|
|
59
|
|
|
$config = services('config'); |
60
|
|
|
|
61
|
|
|
if ($countArgs == 1) { |
62
|
|
|
return call_user_func_array([&$config, 'getItem'], $args); |
63
|
|
|
} else { |
64
|
|
|
return call_user_func_array([&$config, 'loadFile'], $args); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return services('config'); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// ------------------------------------------------------------------------ |
74
|
|
|
|
75
|
|
|
if ( ! function_exists('cache')) { |
76
|
|
|
/** |
77
|
|
|
* cache |
78
|
|
|
* |
79
|
|
|
* Convenient shortcut for O2System Framework Cache service. |
80
|
|
|
* |
81
|
|
|
* @return O2System\Framework\Services\Cache|boolean Returns FALSE if service not exists. |
82
|
|
|
*/ |
83
|
|
|
function cache() |
84
|
|
|
{ |
85
|
|
|
if(services()->has('cache')) { |
|
|
|
|
86
|
|
|
return services()->get('cache'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return false; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// ------------------------------------------------------------------------ |
94
|
|
|
|
95
|
|
|
if ( ! function_exists('hooks')) { |
96
|
|
|
/** |
97
|
|
|
* hooks |
98
|
|
|
* |
99
|
|
|
* Convenient shortcut for O2System Framework Hooks service. |
100
|
|
|
* |
101
|
|
|
* @return O2System\Framework\Services\Hooks Returns FALSE if service not exists. |
102
|
|
|
*/ |
103
|
|
|
function hooks() |
104
|
|
|
{ |
105
|
|
|
if(services()->has('hooks')) { |
|
|
|
|
106
|
|
|
return services()->get('hooks'); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
return false; |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// ------------------------------------------------------------------------ |
114
|
|
|
|
115
|
|
|
if ( ! function_exists('database')) { |
116
|
|
|
/** |
117
|
|
|
* database |
118
|
|
|
* |
119
|
|
|
* Convenient shortcut for O2System Framework Database Connection pools. |
120
|
|
|
* |
121
|
|
|
* @return O2System\Database\Connections |
122
|
|
|
*/ |
123
|
|
|
function database() |
124
|
|
|
{ |
125
|
|
|
return models()->database; |
|
|
|
|
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// ------------------------------------------------------------------------ |
130
|
|
|
|
131
|
|
|
if ( ! function_exists('models')) { |
132
|
|
|
/** |
133
|
|
|
* models |
134
|
|
|
* |
135
|
|
|
* Convenient shortcut for O2System Framework Models container. |
136
|
|
|
* |
137
|
|
|
* @return O2System\Framework\Containers\Models|O2System\Framework\Models\Sql\Model|O2System\Framework\Models\NoSql\Model |
138
|
|
|
*/ |
139
|
|
|
function models() |
140
|
|
|
{ |
141
|
|
|
$args = func_get_args(); |
142
|
|
|
|
143
|
|
|
if (count($args)) { |
144
|
|
|
return o2system()->models->get($args[ 0 ]); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return o2system()->models; |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
// ------------------------------------------------------------------------ |
152
|
|
|
|
153
|
|
|
if ( ! function_exists('modules')) { |
154
|
|
|
/** |
155
|
|
|
* modules |
156
|
|
|
* |
157
|
|
|
* Convenient shortcut for O2System Framework Modules container. |
158
|
|
|
* |
159
|
|
|
* @return O2System\Framework\Containers\Modules |
160
|
|
|
*/ |
161
|
|
|
function modules() |
162
|
|
|
{ |
163
|
|
|
$args = func_get_args(); |
164
|
|
|
|
165
|
|
|
if (count($args)) { |
166
|
|
|
return o2system()->modules->getModule($args[ 0 ]); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return o2system()->modules; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
// ------------------------------------------------------------------------ |
174
|
|
|
|
175
|
|
|
if ( ! function_exists('router')) { |
176
|
|
|
/** |
177
|
|
|
* router |
178
|
|
|
* |
179
|
|
|
* Convenient shortcut for O2System Framework Router service. |
180
|
|
|
* |
181
|
|
|
* @return O2System\Framework\Http\Router|O2System\Framework\Cli\Router |
|
|
|
|
182
|
|
|
*/ |
183
|
|
|
function router() |
184
|
|
|
{ |
185
|
|
|
return services('router'); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
// ------------------------------------------------------------------------ |
190
|
|
|
|
191
|
|
|
if ( ! function_exists('session')) { |
192
|
|
|
/** |
193
|
|
|
* session |
194
|
|
|
* |
195
|
|
|
* Convenient shortcut for O2System Framework Session service. |
196
|
|
|
* |
197
|
|
|
* @return mixed|O2System\Session |
198
|
|
|
*/ |
199
|
|
|
function session() |
200
|
|
|
{ |
201
|
|
|
$args = func_get_args(); |
202
|
|
|
|
203
|
|
|
if (count($args)) { |
204
|
|
|
if(isset($_SESSION[ $args[0] ])) { |
205
|
|
|
return $_SESSION[ $args[0] ]; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return null; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
return services('session'); |
|
|
|
|
212
|
|
|
} |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// ------------------------------------------------------------------------ |
216
|
|
|
|
217
|
|
|
if ( ! function_exists('middleware')) { |
218
|
|
|
/** |
219
|
|
|
* O2System |
220
|
|
|
* |
221
|
|
|
* Convenient shortcut for O2System Framework Http Middleware service. |
222
|
|
|
* |
223
|
|
|
* @return O2System\Framework\Http\Middleware |
224
|
|
|
*/ |
225
|
|
|
function middleware() |
226
|
|
|
{ |
227
|
|
|
return services('middleware'); |
|
|
|
|
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
// ------------------------------------------------------------------------ |
232
|
|
|
|
233
|
|
|
if ( ! function_exists('view')) { |
234
|
|
|
/** |
235
|
|
|
* view |
236
|
|
|
* |
237
|
|
|
* Convenient shortcut for O2System Framework View service. |
238
|
|
|
* |
239
|
|
|
* @return O2System\Framework\Http\View|string |
240
|
|
|
*/ |
241
|
|
|
function view() |
242
|
|
|
{ |
243
|
|
|
$args = func_get_args(); |
244
|
|
|
|
245
|
|
|
if (count($args)) { |
246
|
|
|
if(services()->has('view')) { |
|
|
|
|
247
|
|
|
$view = services('view'); |
248
|
|
|
|
249
|
|
|
return call_user_func_array([&$view, 'load'], $args); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
return false; |
|
|
|
|
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
return services('view'); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
// ------------------------------------------------------------------------ |
260
|
|
|
|
261
|
|
|
if ( ! function_exists('parser')) { |
262
|
|
|
/** |
263
|
|
|
* parser |
264
|
|
|
* |
265
|
|
|
* Convenient shortcut for O2System Parser service. |
266
|
|
|
* |
267
|
|
|
* @return O2System\Framework\Http\Parser |
268
|
|
|
*/ |
269
|
|
|
function parser() |
270
|
|
|
{ |
271
|
|
|
return services('parser'); |
|
|
|
|
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
// ------------------------------------------------------------------------ |
276
|
|
|
|
277
|
|
|
if ( ! function_exists('presenter')) { |
278
|
|
|
/** |
279
|
|
|
* presenter |
280
|
|
|
* |
281
|
|
|
* Convenient shortcut for O2System Framework Http Presenter service. |
282
|
|
|
* |
283
|
|
|
* @return O2System\Framework\Http\Presenter|object |
284
|
|
|
*/ |
285
|
|
|
function presenter() |
286
|
|
|
{ |
287
|
|
|
return services('presenter'); |
|
|
|
|
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
// ------------------------------------------------------------------------ |
292
|
|
|
|
293
|
|
|
if ( ! function_exists('controller')) { |
294
|
|
|
/** |
295
|
|
|
* controller |
296
|
|
|
* |
297
|
|
|
* Convenient shortcut for O2System Framework Controller service. |
298
|
|
|
* |
299
|
|
|
* @return O2System\Framework\Http\Controller|bool |
300
|
|
|
*/ |
301
|
|
|
function controller() |
302
|
|
|
{ |
303
|
|
|
$args = func_get_args(); |
304
|
|
|
|
305
|
|
|
if (count($args)) { |
306
|
|
|
$controller = services()->get('controller'); |
|
|
|
|
307
|
|
|
|
308
|
|
|
return call_user_func_array([&$controller, '__call'], $args); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
return services('controller'); |
312
|
|
|
} |
313
|
|
|
} |