-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
564 lines (523 loc) · 12.8 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?php
use Tamedevelopers\Support\Env;
use Tamedevelopers\Support\PDF;
use Tamedevelopers\Support\Str;
use Tamedevelopers\Support\Zip;
use Tamedevelopers\Support\Hash;
use Tamedevelopers\Support\Mail;
use Tamedevelopers\Support\Tame;
use Tamedevelopers\Support\Time;
use Tamedevelopers\Support\View;
use Tamedevelopers\Support\Asset;
use Tamedevelopers\Support\Cookie;
use Tamedevelopers\Support\Server;
use Tamedevelopers\Support\Country;
use Tamedevelopers\Support\UrlHelper;
use Tamedevelopers\Support\Translator;
use Tamedevelopers\Support\NumberToWords;
use Tamedevelopers\Support\AutoloadRegister;
use Tamedevelopers\Support\Capsule\FileCache;
use Tamedevelopers\Support\Collections\Collection;
if (! function_exists('AppIsNotCorePHP')) {
/**
* Check if Application is not Core PHP
* If running on other frameworks
*
* @return bool
*/
function AppIsNotCorePHP()
{
// using `get_declared_classes()` function will return all classes in your project
// Check if any classe exist
return Tame::checkAnyClassExists([
'\Illuminate\Foundation\Application',
// '\CI_Controller',
// '\Cake\Controller\Controller',
// '\Symfony\Component\HttpKernel\Kernel',
// '\Symfony\Component\Routing\Annotation\Route',
]);
}
}
if (! function_exists('Tame')) {
/**
* Tame Object
*
* @return \Tamedevelopers\Support\Tame
*/
function Tame()
{
return new Tame();
}
}
if (! function_exists('TameMail')) {
/**
* Mailer Object
*
* @return \Tamedevelopers\Support\Mail
*/
function TameMail()
{
return new Mail();
}
}
if (! function_exists('TameCookie')) {
/**
* Cookie Object
*
* @return \Tamedevelopers\Support\Cookie
*/
function TameCookie()
{
return new Cookie();
}
}
if (! function_exists('TameTime')) {
/**
* Time Object
* @param int|string|null $time
* @param string|null $timezone
* @return \Tamedevelopers\Support\Time
*/
function TameTime($time = null, $timezone = null)
{
return new Time($time, $timezone);
}
}
if (! function_exists('TameCollect')) {
/**
* Collection of data
*
* @param array $items
*
* @return \Tamedevelopers\Support\Collections\Collection
*/
function TameCollect($items = [])
{
return new Collection($items);
}
}
if (! function_exists('TameStr')) {
/**
* Tame Str
*
* @return \Tamedevelopers\Support\Str
*/
function TameStr()
{
return new Str();
}
}
if (! function_exists('TameCountry')) {
/**
* Country Object
* @return \Tamedevelopers\Support\Country
*/
function TameCountry()
{
return new Country();
}
}
if (! function_exists('NumberToWords')) {
/**
* NumberToWords Object
* @return \Tamedevelopers\Support\NumberToWords
*/
function NumberToWords()
{
return new NumberToWords();
}
}
if (! function_exists('TamePDF')) {
/**
* PDF Object
*
* @return \Tamedevelopers\Support\PDF
*/
function TamePDF()
{
return new PDF();
}
}
if (! function_exists('TameZip')) {
/**
* Zip Object
*
* @return \Tamedevelopers\Support\Zip
*/
function TameZip()
{
return new Zip();
}
}
if (! AppIsNotCorePHP() && ! function_exists('bcrypt')) {
/**
* Password Encrypter.
* This function encrypts a password using bcrypt with a generated salt.
*
* @param string $password
* - The password to encrypt.
*
* @return string
* - The encrypted password.
*/
function bcrypt($password)
{
return Hash::make($password);
}
}
if (! function_exists('FileCache')) {
/**
* File Cache Object
*
* @return \Tamedevelopers\Support\Capsule\FileCache
*/
function FileCache()
{
return new FileCache();
}
}
if (! function_exists('server')) {
/**
* Server Object
*
* @return \Tamedevelopers\Support\Server
*/
function server()
{
return new Server();
}
}
if (! function_exists('autoload_register')) {
/**
* Autoload function to load class and files in a given folder
*
* @param string|array $baseDirectory
* - The directory path to load
* - Do not include the root path, as The Application already have a copy of your path
* - e.g 'classes' or ['app/main', 'includes']
*
* @return \Tamedevelopers\Support\AutoloadRegister
*/
function autoload_register(string|array $directory)
{
(new AutoloadRegister)->load($directory);
}
}
if (! AppIsNotCorePHP() && ! function_exists('config')) {
/**
* Get the value of a configuration option.
*
* @param mixed $key
* The configuration key in dot notation (e.g., 'database.connections.mysql')
*
* @param mixed $default
* [optional] The default value to return if the configuration option is not found
*
* @return mixed
* The value of the configuration option, or null if it doesn't exist
*/
function config($key, $default = null)
{
return server()->config($key, $default);
}
}
if (! AppIsNotCorePHP() && ! function_exists('env')) {
/**
* Get ENV (Enviroment) Data
* - If .env was not used,
* - Then it will get all App Configuration Data as well
*
* @param string|null $key
* - [optional] ENV KEY or APP Configuration Key
*
* @param mixed $value
* - [optional] Default value if key not found
*
* @return mixed
*/
function env($key = null, $value = null)
{
return Env::env($key, $value);
}
}
if (! function_exists('env_update')) {
/**
* Update Environment [path .env] variables
*
* @param string|null $key \Environment key you want to update
*
* @param string|bool|null $value \Value of Variable to update
*
* @param bool $quote \Default is true
* [optional] Allow quotes around values
*
* @param bool $space \Default is false
* [optional] Allow space between key and value
*
* @return bool
*/
function env_update($key = null, $value = null, ?bool $quote = true, ?bool $space = false)
{
return Env::updateENV($key, $value, $quote, $space);
}
}
if (! function_exists('tview')) {
/**
* View Tenmplate Engine
*
* @param string $viewPath The path to the view file.
* @param array $data The data to be passed to the view.
*
* @return Tamedevelopers\Support\View
*/
function tview($viewPath, $data = [])
{
return new View($viewPath, $data);
}
}
if (! function_exists('tasset')) {
/**
* Create assets Real path url
*
* @param string $asset
* - asset file e.g (style.css | js/main.js)
*
* @param bool|null $cache
*
* @param bool|null $path_type
* -[optional] Default is false (Absolute Path)|Else -- False is (Relative path)
*
* @return string
*/
function tasset($asset = null, $cache = null, $path_type = null)
{
return Asset::asset($asset, $cache, $path_type);
}
}
if (! function_exists('config_asset')) {
/**
* Configure Assets Default Directory
*
* @param string|null $base_path
* - [optional] Default is `base_directory/assets`
* - If set and directory is not found, then we revert back to the default
*
* @param bool $cache
* - [optional] Default is false
* - End point of link `?v=xxxxxxxx` is with cache of file time change
* - This will automatically tells the broswer to fetch new file if the time change
* - Time will only change if you make changes or modify the request file
*
* @param bool $path_type
* -[optional] Default is false (Absolute Path)|Else -- False is (Relative path)
*
* @return void
*/
function config_asset($base_path = null, ?bool $cache = false, ?bool $path_type = false)
{
Asset::config($base_path, $cache, $path_type);
}
}
if (! AppIsNotCorePHP() && ! function_exists('__')) {
/**
* Translate the given message.
*
* @param string|null $key
* @param string|null $locale
* @param string|null $base_folder
*
* @return string|array|null
*/
function __($key = null, $locale = null, $base_folder = null)
{
if (is_null($key)) {
return $key;
}
return Translator::trans($key, $locale, $base_folder);
}
}
if (! function_exists('base_path')) {
/**
* Get Base Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/server_path/path
*
* @return string
*/
function base_path($path = null)
{
return server()->formatWithBaseDirectory($path);
}
}
if (! function_exists('directory')) {
/**
* Get Base Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/server_path/path
*
* @return string
*/
function directory($path = null)
{
return base_path($path);
}
}
if (! function_exists('storage_path')) {
/**
* Get Storage Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/storage/path
*
* @return string
*/
function storage_path($path = null)
{
return base_path("storage/{$path}");
}
}
if (! function_exists('public_path')) {
/**
* Get Public Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/public/path
*
* @return string
*/
function public_path($path = null)
{
return base_path("public/{$path}");
}
}
if (! function_exists('app_path')) {
/**
* Get Storage Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/app/path
*
* @return string
*/
function app_path($path = null)
{
return base_path("app/{$path}");
}
}
if (! function_exists('config_path')) {
/**
* Get Config Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/server_path/path
*
* @return string
*/
function config_path($path = null)
{
return base_path("config/{$path}");
}
}
if (! function_exists('lang_path')) {
/**
* Get Config Directory `Path`
* @param string|null $path
* - [optional] You can pass a path to include with the base directory
* - Final result: i.e C:/lang/path
*
* @return string
*/
function lang_path($path = null)
{
return base_path("lang/{$path}");
}
}
if (! function_exists('domain')) {
/**
* Get Domain `URL` URI
*
* @param string|null $path
* - [optional] You can pass a path to include with the domain link
* - Final result: i.e https://domain.com/path
*
* @return string
*/
function domain($path = null)
{
return server()->formatWithDomainURI($path);
}
}
if (! function_exists('urlHelper')) {
/**
* Get URL Helper
*
* @return \Tamedevelopers\Support\UrlHelper
*/
function urlHelper()
{
return new UrlHelper();
}
}
if (! function_exists('to_array')) {
/**
* Convert Value to an Array
*
* @param mixed $value
* @return array
*/
function to_array($value)
{
return server()->toArray($value);
}
}
if (! function_exists('to_object')) {
/**
* Convert Value to an Object
*
* @param mixed $value
* @return object
*/
function to_object($value)
{
return server()->toObject($value);
}
}
if (! function_exists('to_json')) {
/**
* Convert Value to Json Data
*
* @param mixed $value
* @return string
*/
function to_json($value)
{
return server()->toJson($value);
}
}
if (! AppIsNotCorePHP() && ! function_exists('dump')) {
/**
* Dump Data
* @param mixed $data
*
* @return void
*/
function dump(...$data)
{
server()->dump($data);
}
}
if (! AppIsNotCorePHP() && ! function_exists('dd')) {
/**
* Dump and Data
* @param mixed $data
*
* @return void
*/
function dd(...$data)
{
dump($data);
exit(1);
}
}