1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
use Faker\Factory;
|
4
|
|
|
use Faker\Generator;
|
|
|
|
|
5
|
|
|
use Resta\Support\Filesystem;
|
6
|
|
|
use Resta\Logger\LoggerHandler;
|
7
|
|
|
use Store\Services\RequestService;
|
|
|
|
|
8
|
|
|
use Resta\Exception\ExceptionManager;
|
9
|
|
|
use Resta\Support\HigherOrderTapProxy;
|
10
|
|
|
use Resta\Response\ResponseOutManager;
|
11
|
|
|
use Resta\Contracts\ContainerContracts;
|
12
|
|
|
use Resta\EventDispatcher\EventManager;
|
13
|
|
|
use Resta\Contracts\ExceptionContracts;
|
14
|
|
|
use Resta\Contracts\StaticPathContracts;
|
15
|
|
|
use Resta\Contracts\ApplicationContracts;
|
16
|
|
|
use Resta\Foundation\ApplicationProvider;
|
17
|
|
|
use Resta\Authenticate\AuthenticateContract;
|
18
|
|
|
use Resta\Authenticate\AuthenticateProvider;
|
19
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
20
|
|
|
use Resta\Contracts\ApplicationHelpersContracts;
|
21
|
|
|
use Resta\Foundation\PathManager\StaticPathList;
|
22
|
|
|
|
23
|
|
|
if (!function_exists('app')) {
|
24
|
|
|
|
25
|
|
|
/**
|
26
|
|
|
* @return ApplicationContracts|ApplicationHelpersContracts
|
27
|
|
|
*/
|
28
|
|
|
function app()
|
29
|
|
|
{
|
30
|
|
|
return appInstance();
|
|
|
|
|
31
|
|
|
}
|
32
|
|
|
}
|
33
|
|
|
|
34
|
|
|
if (!function_exists('appInstance')) {
|
35
|
|
|
|
36
|
|
|
/**
|
37
|
|
|
* @return ApplicationProvider
|
38
|
|
|
*/
|
39
|
|
|
function appInstance()
|
40
|
|
|
{
|
41
|
|
|
return \application::getAppInstance();
|
|
|
|
|
42
|
|
|
}
|
43
|
|
|
}
|
44
|
|
|
|
45
|
|
|
if (!function_exists('applicationKey')) {
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* @return string
|
49
|
|
|
*/
|
50
|
|
|
function applicationKey()
|
51
|
|
|
{
|
52
|
|
|
if(property_exists($kernel=app()->kernel(),'applicationKey')){
|
|
|
|
|
53
|
|
|
return $kernel->applicationKey;
|
54
|
|
|
}
|
55
|
|
|
return null;
|
56
|
|
|
|
57
|
|
|
}
|
58
|
|
|
}
|
59
|
|
|
|
60
|
|
|
if (!function_exists('auth')) {
|
61
|
|
|
/**
|
62
|
|
|
* @return AuthenticateContract
|
63
|
|
|
*/
|
64
|
|
|
function auth()
|
65
|
|
|
{
|
66
|
|
|
return app()->resolve(AuthenticateProvider::class);
|
|
|
|
|
67
|
|
|
}
|
68
|
|
|
}
|
69
|
|
|
|
70
|
|
|
if (!function_exists('bind')) {
|
71
|
|
|
|
72
|
|
|
function bind()
|
|
|
|
|
73
|
|
|
{
|
74
|
|
|
return (object)app()['serviceContainer'];
|
75
|
|
|
}
|
76
|
|
|
}
|
77
|
|
|
|
78
|
|
|
if (!function_exists('bundleName')) {
|
79
|
|
|
|
80
|
|
|
/**
|
81
|
|
|
* @return null|string
|
82
|
|
|
*/
|
83
|
|
|
function bundleName()
|
84
|
|
|
{
|
85
|
|
|
if(defined('endpoint')){
|
86
|
|
|
|
87
|
|
|
return endpoint.''.StaticPathList::$controllerBundleName;
|
88
|
|
|
}
|
89
|
|
|
return null;
|
90
|
|
|
}
|
91
|
|
|
}
|
92
|
|
|
|
93
|
|
|
if (!function_exists('config')) {
|
94
|
|
|
|
95
|
|
|
/**
|
96
|
|
|
* @param null $config
|
|
|
|
|
97
|
|
|
* @param null $default
|
|
|
|
|
98
|
|
|
* @return mixed|null
|
99
|
|
|
*/
|
100
|
|
|
function config($config=null,$default=null)
|
101
|
|
|
{
|
102
|
|
|
$configResult = app()->config($config);
|
|
|
|
|
103
|
|
|
|
104
|
|
|
if($configResult === null && $default!==null){
|
|
|
|
|
105
|
|
|
return $default;
|
106
|
|
|
}
|
107
|
|
|
|
108
|
|
|
return $configResult;
|
109
|
|
|
}
|
110
|
|
|
}
|
111
|
|
|
|
112
|
|
|
if (!function_exists('container')) {
|
113
|
|
|
|
114
|
|
|
/**
|
115
|
|
|
* @param $class
|
116
|
|
|
* @param $bind array
|
117
|
|
|
* @return mixed
|
118
|
|
|
*/
|
119
|
|
|
function container($class,$bind=array())
|
120
|
|
|
{
|
121
|
|
|
return app()->singleton()->appClass->container(appInstance(),$class,$bind);
|
|
|
|
|
122
|
|
|
}
|
123
|
|
|
}
|
124
|
|
|
|
125
|
|
|
if (!function_exists('core')) {
|
126
|
|
|
|
127
|
|
|
/**
|
128
|
|
|
* @return mixed
|
129
|
|
|
*/
|
130
|
|
|
function core()
|
131
|
|
|
{
|
132
|
|
|
return app()->singleton();
|
133
|
|
|
}
|
134
|
|
|
}
|
135
|
|
|
|
136
|
|
|
if (!function_exists('dd')) {
|
137
|
|
|
function dd()
|
138
|
|
|
{
|
139
|
|
|
$args = func_get_args();
|
140
|
|
|
call_user_func_array('dump', $args);
|
141
|
|
|
die();
|
|
|
|
|
142
|
|
|
}
|
143
|
|
|
}
|
144
|
|
|
|
145
|
|
|
if (!function_exists('files')) {
|
146
|
|
|
|
147
|
|
|
/**
|
148
|
|
|
* @return Filesystem
|
149
|
|
|
*/
|
150
|
|
|
function files() : Filesystem
|
151
|
|
|
{
|
152
|
|
|
return app()->resolve(Filesystem::class);
|
153
|
|
|
}
|
154
|
|
|
}
|
155
|
|
|
|
156
|
|
|
if (!function_exists('environment')) {
|
157
|
|
|
function environment()
|
|
|
|
|
158
|
|
|
{
|
159
|
|
|
return app()->environment(func_get_args());
|
|
|
|
|
160
|
|
|
}
|
161
|
|
|
}
|
162
|
|
|
|
163
|
|
|
if (!function_exists('event')) {
|
164
|
|
|
|
165
|
|
|
/**
|
166
|
|
|
* @return EventManager
|
167
|
|
|
*/
|
168
|
|
|
function event()
|
169
|
|
|
{
|
170
|
|
|
return app()->singleton()->bindings['eventDispatcher'];
|
171
|
|
|
}
|
172
|
|
|
}
|
173
|
|
|
|
174
|
|
|
if (!function_exists('exception')) {
|
175
|
|
|
|
176
|
|
|
/**
|
177
|
|
|
* @param null $name
|
|
|
|
|
178
|
|
|
* @param array $params
|
179
|
|
|
* @return ExceptionContracts
|
180
|
|
|
*/
|
181
|
|
|
function exception($name=null,$params=array())
|
182
|
|
|
{
|
183
|
|
|
$exceptionManager=ExceptionManager::class;
|
184
|
|
|
return app()->resolve($exceptionManager,['name'=>$name,'params'=>$params]);
|
185
|
|
|
}
|
186
|
|
|
}
|
187
|
|
|
|
188
|
|
|
if (!function_exists('faker')) {
|
189
|
|
|
|
190
|
|
|
/**
|
191
|
|
|
* @param null $locale
|
|
|
|
|
192
|
|
|
* @return Generator
|
193
|
|
|
*/
|
194
|
|
|
function faker($locale=null)
|
|
|
|
|
195
|
|
|
{
|
196
|
|
|
if($locale===null){
|
|
|
|
|
197
|
|
|
$faker=Factory::create();
|
198
|
|
|
}
|
199
|
|
|
else{
|
200
|
|
|
$faker=Factory::create($locale);
|
201
|
|
|
}
|
202
|
|
|
|
203
|
|
|
return $faker;
|
204
|
|
|
}
|
205
|
|
|
}
|
206
|
|
|
|
207
|
|
|
if (!function_exists('fingerPrint')) {
|
208
|
|
|
|
209
|
|
|
function fingerPrint()
|
210
|
|
|
{
|
211
|
|
|
return md5(sha1(implode("|",[
|
212
|
|
|
request()->getClientIp(),$_SERVER['HTTP_USER_AGENT'],applicationKey()
|
213
|
|
|
])));
|
214
|
|
|
}
|
215
|
|
|
}
|
216
|
|
|
|
217
|
|
|
if (!function_exists('fullUrl')) {
|
218
|
|
|
|
219
|
|
|
function fullUrl()
|
220
|
|
|
{
|
221
|
|
|
return request()->getUri();
|
222
|
|
|
}
|
223
|
|
|
}
|
224
|
|
|
|
225
|
|
|
if (!function_exists('get')) {
|
226
|
|
|
|
227
|
|
|
/**
|
228
|
|
|
* @param null $param
|
|
|
|
|
229
|
|
|
* @param null $default
|
|
|
|
|
230
|
|
|
* @return null
|
231
|
|
|
*/
|
232
|
|
|
function get($param=null,$default=null)
|
233
|
|
|
{
|
234
|
|
|
//symfony request query object
|
235
|
|
|
$get=core()->get;
|
236
|
|
|
|
237
|
|
|
return ($param===null) ? $get : (isset($get[$param]) ? $get[$param] : $default);
|
|
|
|
|
238
|
|
|
}
|
239
|
|
|
}
|
240
|
|
|
|
241
|
|
|
if (!function_exists('headers')) {
|
242
|
|
|
|
243
|
|
|
/**
|
244
|
|
|
* @param null $param
|
|
|
|
|
245
|
|
|
* @param null $default
|
|
|
|
|
246
|
|
|
* @return array
|
247
|
|
|
*/
|
248
|
|
|
function headers($param=null,$default=null)
|
249
|
|
|
{
|
250
|
|
|
$list=[];
|
251
|
|
|
|
252
|
|
|
//We only get the objects in the list name to match the header objects
|
253
|
|
|
//that come with the request path to the objects sent by the client
|
254
|
|
|
foreach (request()->headers->all() as $key=>$value) {
|
255
|
|
|
$list[$key]=$value;
|
256
|
|
|
}
|
257
|
|
|
|
258
|
|
|
//return header list
|
259
|
|
|
return ($param===null) ? $list : (isset($list[$param]) ? $list[$param][0] : $default);
|
|
|
|
|
260
|
|
|
}
|
261
|
|
|
}
|
262
|
|
|
|
263
|
|
|
if (!function_exists('httpMethod')) {
|
264
|
|
|
|
265
|
|
|
/**
|
266
|
|
|
* @return string
|
267
|
|
|
*/
|
268
|
|
|
function httpMethod()
|
269
|
|
|
{
|
270
|
|
|
return strtolower(core()->httpMethod);
|
271
|
|
|
}
|
272
|
|
|
}
|
273
|
|
|
|
274
|
|
|
if (!function_exists('logger')) {
|
275
|
|
|
|
276
|
|
|
/**
|
277
|
|
|
* @param $file null
|
|
|
|
|
278
|
|
|
* @return LoggerHandler
|
279
|
|
|
*/
|
280
|
|
|
function logger($file=null)
|
281
|
|
|
{
|
282
|
|
|
return app()->resolve(LoggerHandler::class,['file'=>$file]);
|
283
|
|
|
}
|
284
|
|
|
}
|
285
|
|
|
|
286
|
|
|
if (!function_exists('request')) {
|
287
|
|
|
|
288
|
|
|
/**
|
289
|
|
|
* @return RequestService|Request
|
290
|
|
|
*/
|
291
|
|
|
function request()
|
|
|
|
|
292
|
|
|
{
|
293
|
|
|
return core()->request;
|
294
|
|
|
}
|
295
|
|
|
}
|
296
|
|
|
|
297
|
|
|
if (!function_exists('response')) {
|
298
|
|
|
|
299
|
|
|
/**
|
300
|
|
|
* @return ResponseOutManager
|
301
|
|
|
*/
|
302
|
|
|
function response()
|
303
|
|
|
{
|
304
|
|
|
$object=debug_backtrace()[1]['object'];
|
305
|
|
|
return new ResponseOutManager($object);
|
306
|
|
|
}
|
307
|
|
|
}
|
308
|
|
|
|
309
|
|
|
if (!function_exists('resolve')) {
|
310
|
|
|
|
311
|
|
|
/**
|
312
|
|
|
* @param $class
|
313
|
|
|
* @param array $bind
|
314
|
|
|
* @return mixed|null
|
315
|
|
|
*
|
316
|
|
|
* @throws \DI\DependencyException
|
317
|
|
|
* @throws \DI\NotFoundException
|
318
|
|
|
*/
|
319
|
|
|
function resolve($class,$bind=array())
|
320
|
|
|
{
|
321
|
|
|
return app()->resolve($class,$bind);
|
322
|
|
|
}
|
323
|
|
|
}
|
324
|
|
|
|
325
|
|
|
if (!function_exists('route')) {
|
326
|
|
|
|
327
|
|
|
/**
|
328
|
|
|
* @param $key
|
329
|
|
|
* @return mixed
|
330
|
|
|
*/
|
331
|
|
|
function route($key=null)
|
332
|
|
|
{
|
333
|
|
|
return array_map(function($route){
|
334
|
|
|
return strtolower($route);
|
335
|
|
|
},app()->singleton()->appClass->route($key));
|
336
|
|
|
}
|
337
|
|
|
}
|
338
|
|
|
|
339
|
|
|
if (!function_exists('path')) {
|
340
|
|
|
|
341
|
|
|
/**
|
342
|
|
|
* @return StaticPathContracts
|
343
|
|
|
*/
|
344
|
|
|
function path()
|
345
|
|
|
{
|
346
|
|
|
return app()->path();
|
347
|
|
|
}
|
348
|
|
|
}
|
349
|
|
|
|
350
|
|
|
if (!function_exists('post')) {
|
351
|
|
|
|
352
|
|
|
/**
|
353
|
|
|
* @param null $param
|
|
|
|
|
354
|
|
|
* @param null $default
|
|
|
|
|
355
|
|
|
* @return mixed
|
356
|
|
|
*/
|
357
|
|
|
function post($param=null,$default=null)
|
358
|
|
|
{
|
359
|
|
|
//symfony request query object
|
360
|
|
|
$post=core()->post;
|
361
|
|
|
|
362
|
|
|
return ($param===null) ? $post : (isset($post[$param]) ? $post[$param] : $default);
|
|
|
|
|
363
|
|
|
}
|
364
|
|
|
}
|
365
|
|
|
|
366
|
|
|
if (!function_exists('tap')) {
|
367
|
|
|
|
368
|
|
|
/**
|
369
|
|
|
* @param $value
|
370
|
|
|
* @param $callback
|
371
|
|
|
* @return mixed
|
372
|
|
|
*/
|
373
|
|
|
function tap($value, $callback)
|
374
|
|
|
{
|
375
|
|
|
if (!is_callable($callback)) {
|
376
|
|
|
return new HigherOrderTapProxy($value);
|
377
|
|
|
}
|
378
|
|
|
|
379
|
|
|
$callback($value);
|
380
|
|
|
return $value;
|
381
|
|
|
}
|
382
|
|
|
}
|
383
|
|
|
|
384
|
|
|
if (!function_exists('trans')) {
|
385
|
|
|
|
386
|
|
|
/**
|
387
|
|
|
* @param $lang
|
388
|
|
|
* @param array $select
|
389
|
|
|
* @return mixed
|
390
|
|
|
*/
|
391
|
|
|
function trans($lang,$select=array())
|
392
|
|
|
{
|
393
|
|
|
return app()->singleton()->appClass->translator($lang,$select);
|
394
|
|
|
}
|
395
|
|
|
} |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: