Passed
Push — main ( 5eb528...8b73d6 )
by Dimitri
12:35
created

root_path()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Blitz PHP framework.
5
 *
6
 * (c) 2022 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
if (! function_exists('css_path')) {
13
    /**
14
     * CSS PATH
15
     *
16
     * Renvoie le chemin absolu d'un fichier css.
17
     *
18
     * @param string $name nom du fichier dont on veut avoir le chemin
19
     */
20
    function css_path(string $name = ''): string
21
    {
22
        if (! empty($name)) {
23
            $name = DS . ltrim($name, '/\\');
24
        }
25
26
        return WEBROOT . 'css' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
    }
28
}
29
30
if (! function_exists('js_path')) {
31
    /**
32
     * JS PATH
33
     *
34
     * Renvoie le chemin absolu d'un fichier js.
35
     *
36
     * @param string $name nom du fichier dont on veut avoir le chemin
37
     */
38
    function js_path(string $name = ''): string
39
    {
40
        if (! empty($name)) {
41
            $name = DS . ltrim($name, '/\\');
42
        }
43
44
        return WEBROOT . 'js' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
    }
46
}
47
48
if (! function_exists('lib_path')) {
49
    /**
50
     * LIB PATH
51
     *
52
     * Renvoie le chemin absolu d'un fichier d'une librairie
53
     *
54
     * @param string $name nom du fichier dont on veut avoir le chemin
55
     */
56
    function lib_path(string $name = ''): string
57
    {
58
        if (! empty($name)) {
59
            $name = DS . ltrim($name, '/\\');
60
        }
61
62
        return WEBROOT . 'lib' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
63
    }
64
}
65
66
if (! function_exists('less_path')) {
67
    /**
68
     * LESS PATH
69
     *
70
     * Renvoie le chemin absolu d'un fichier less.
71
     *
72
     * @param string $name nom du fichier dont on veut avoir le chemin
73
     */
74
    function less_path(string $name = ''): string
75
    {
76
        if (! empty($name)) {
77
            $name = DS . ltrim($name, '/\\');
78
        }
79
80
        return WEBROOT . 'less' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
81
    }
82
}
83
84
if (! function_exists('img_path')) {
85
    /**
86
     * IMG PATH
87
     *
88
     * Renvoie le chemin absolu d'une image
89
     *
90
     * @param string $name nom du fichier dont on veut avoir le chemin
91
     */
92
    function img_path(string $name = ''): string
93
    {
94
        if (! empty($name)) {
95
            $name = DS . ltrim($name, '/\\');
96
        }
97
98
        return WEBROOT . 'img' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
99
    }
100
}
101
102
if (! function_exists('docs_path')) {
103
    /**
104
     * DOCS PATH
105
     *
106
     * Renvoie le chemin absolu d'un document
107
     *
108
     * @param string $name nom du fichier dont on veut avoir le chemin
109
     */
110
    function docs_path(string $name = ''): string
111
    {
112
        if (! empty($name)) {
113
            $name = DS . ltrim($name, '/\\');
114
        }
115
116
        return WEBROOT . 'docs' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
117
    }
118
}
119
120
if (! function_exists('video_path')) {
121
    /**
122
     * VIDEO PATH
123
     *
124
     * Renvoie le chemin absolu d'une vidéo
125
     *
126
     * @param string $name nom du fichier dont on veut avoir le chemin
127
     */
128
    function video_path(string $name = ''): string
129
    {
130
        if (! empty($name)) {
131
            $name = DS . ltrim($name, '/\\');
132
        }
133
134
        return WEBROOT . 'videos' . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
135
    }
136
}
137
138
if (! function_exists('public_path')) {
139
    /**
140
     * PUBLIC PATH
141
     *
142
     * Renvoie le chemin absolu du dossier public
143
     *
144
     * @param string $name nom du fichier dont on veut avoir le chemin
145
     */
146
    function public_path(string $name = ''): string
147
    {
148
        if (! empty($name)) {
149
            $name = ltrim($name, '/\\');
150
        }
151
152
        return WEBROOT . str_replace('/', DS, $name);
0 ignored issues
show
Bug introduced by
The constant WEBROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
153
    }
154
}
155
156
if (! function_exists('root_path')) {
157
    /**
158
     * ROOT PATH
159
     *
160
     * Renvoie le chemin absolu du dossier racine
161
     *
162
     * @param string $name nom du fichier dont on veut avoir le chemin
163
     */
164
    function root_path(string $name = ''): string
165
    {
166
        if (! empty($name)) {
167
            $name = ltrim($name, '/\\');
168
        }
169
170
        return ROOTPATH . str_replace('/', DS, $name);
171
    }
172
}
173
174
if (! function_exists('base_path')) {
175
    /**
176
     * BASE PATH
177
     *
178
     * Renvoie le chemin absolu du dossier de base
179
     *
180
     * @param string $name nom du fichier dont on veut avoir le chemin
181
     */
182
    function base_path(string $name = ''): string
183
    {
184
        if (! empty($name)) {
185
            $name = ltrim($name, '/\\');
186
        }
187
188
        return BASEPATH . str_replace('/', DS, $name);
189
    }
190
}
191
192
if (! function_exists('class_path')) {
193
    /**
194
     * CLASS PATH
195
     *
196
     * Renvoie le chemin absolu d'une classe applicative
197
     *
198
     * @param string $name nom du fichier dont on veut avoir le chemin
199
     */
200
    function class_path(string $name = ''): string
201
    {
202
        if (! empty($name)) {
203
            $name = DS . ltrim($name, '/\\');
204
        }
205
206
        return APP_PATH . 'class' . str_replace('/', DS, $name);
207
    }
208
}
209
210
if (! function_exists('config_path')) {
211
    /**
212
     * CONFIG PATH
213
     *
214
     * Renvoie le chemin absolu d'un fichier de configuration
215
     *
216
     * @param string $name nom du fichier dont on veut avoir le chemin
217
     */
218
    function config_path(string $name = ''): string
219
    {
220
        if (! empty($name)) {
221
            $name = DS . ltrim($name, '/\\');
222
        }
223
224
        return APP_PATH . 'config' . str_replace('/', DS, $name);
225
    }
226
}
227
228
if (! function_exists('controller_path')) {
229
    /**
230
     * CONTROLLER PATH
231
     *
232
     * Renvoie le chemin absolu d'un contrôleur
233
     *
234
     * @param string $name nom du fichier dont on veut avoir le chemin
235
     * @param bool   $only specifie si on veut seulement les contrôleurs (fichier php ayant le suffixe Controller)
236
     */
237
    function controller_path(string $name = '', bool $only = true): string
238
    {
239
        if (! empty($name)) {
240
            $name = ltrim($name, '/\\');
241
242
            if ($only === true && ! preg_match('#Controller\.php$#', $name)) {
243
                $name = ucfirst(strtolower($name)) . 'Controller.php';
244
            }
245
        }
246
247
        return CONTROLLER_PATH . str_replace('/', DS, $name);
248
    }
249
}
250
251
if (! function_exists('entity_path')) {
252
    /**
253
     * ENTITY PATH
254
     *
255
     * Renvoie le chemin absolu d'une entité
256
     *
257
     * @param string $name nom du fichier dont on veut avoir le chemin
258
     * @param bool   $only specifie si on veut seulement les fichiers d'entité (fichiers php ayant le suffixe Entity)
259
     */
260
    function entity_path(string $name = '', bool $only = true): string
261
    {
262
        if (! empty($name)) {
263
            $name = ltrim($name, '/\\');
264
265
            if ($only === true && ! preg_match('#Entity\.php$#', $name)) {
266
                $name = ucfirst($name) . 'Entity.php';
267
            }
268
        }
269
270
        return ENTITY_PATH . str_replace('/', DS, $name);
271
    }
272
}
273
274
if (! function_exists('helper_path')) {
275
    /**
276
     * HELPER PATH
277
     *
278
     * Renvoie le chemin absolu d'un helper
279
     *
280
     * @param string $name   nom du fichier dont on veut avoir le chemin
281
     * @param bool   $system specifie s'il s'agit des helpers systeme ou applicatif
282
     */
283
    function helper_path(string $name = '', bool $system = false): string
284
    {
285
        if (! empty($name)) {
286
            $name = DS . ltrim($name, '/\\');
287
        }
288
        if ($system === true) {
289
            return SYST_PATH . 'helpers' . str_replace('/', DS, $name);
290
        }
291
292
        return APP_PATH . 'helpers' . str_replace('/', DS, $name);
293
    }
294
}
295
296
if (! function_exists('library_path')) {
297
    /**
298
     * LIBRARY PATH
299
     *
300
     * Renvoie le chemin absolu d'une librairie
301
     *
302
     * @param string $name   nom du fichier dont on veut avoir le chemin
303
     * @param bool   $system specifie s'il s'agit des librairies systeme ou applicatif
304
     */
305
    function library_path(string $name = '', bool $system = false): string
306
    {
307
        if (! empty($name)) {
308
            $name = DS . ltrim($name, '/\\');
309
        }
310
        if ($system === true) {
311
            return SYST_PATH . 'libraries' . str_replace('/', DS, $name);
312
        }
313
314
        return APP_PATH . 'libraries' . str_replace('/', DS, $name);
315
    }
316
}
317
318
if (! function_exists('middleware_path')) {
319
    /**
320
     * MIDDLEWARE PATH
321
     *
322
     * Renvoie le chemin absolu d'un middleware
323
     *
324
     * @param string $name   nom du fichier dont on veut avoir le chemin
325
     * @param bool   $system specifie s'il s'agit des middlewares systeme ou applicatif
326
     * @param bool   $only   specifie si on veut seulement les middlewares (fichiers php ayant le suffixe Middleware)
327
     */
328
    function middleware_path(string $name = '', bool $system = false, bool $only = true): string
329
    {
330
        if (! empty($name)) {
331
            $name = DS . ltrim($name, '/\\');
332
333
            if ($only === true && ! preg_match('#Middleware\.php$#', $name)) {
334
                $name = ucfirst($name) . 'Middleware.php';
335
            }
336
        }
337
        if ($system === true) {
338
            return SYST_PATH . 'middlewares' . str_replace('/', DS, $name);
339
        }
340
341
        return APP_PATH . 'middlewares' . str_replace('/', DS, $name);
342
    }
343
}
344
345
if (! function_exists('model_path')) {
346
    /**
347
     * MODEL PATH
348
     *
349
     * Renvoie le chemin absolu d'un modèle
350
     *
351
     * @param string $name nom du fichier dont on veut avoir le chemin
352
     * @param bool   $only specifie si on veut seulement les modèles (fichiers php ayant le suffixe Model)
353
     */
354
    function model_path(string $name = '', bool $only = true): string
355
    {
356
        if (! empty($name)) {
357
            $name = ltrim($name, '/\\');
358
359
            if ($only === true && ! preg_match('#Model\.php$#', $name)) {
360
                $name = ucfirst(strtolower($name)) . 'Model.php';
361
            }
362
        }
363
364
        return MODEL_PATH . str_replace('/', DS, $name);
365
    }
366
}
367
368
if (! function_exists('resource_path')) {
369
    /**
370
     * RESOURCE PATH
371
     *
372
     * Renvoie le chemin absolu d'un fichier ressource
373
     *
374
     * @param string $name nom du fichier dont on veut avoir le chemin
375
     */
376
    function resource_path(string $name = ''): string
377
    {
378
        if (! empty($name)) {
379
            $name = ltrim($name, '/\\');
380
        }
381
382
        return RESOURCE_PATH . str_replace('/', DS, $name);
383
    }
384
}
385
386
if (! function_exists('migration_path')) {
387
    /**
388
     * MIGRATION PATH
389
     *
390
     * Renvoie le chemin absolu d'un fichier de migration
391
     *
392
     * @param string $name nom du fichier dont on veut avoir le chemin
393
     */
394
    function migration_path(string $name = ''): string
395
    {
396
        if (! empty($name)) {
397
            $name = ltrim($name, '/\\');
398
        }
399
400
        return DB_MIGRATION_PATH . str_replace('/', DS, $name);
401
    }
402
}
403
404
if (! function_exists('seed_path')) {
405
    /**
406
     * SEED PATH
407
     *
408
     * Renvoie le chemin absolu d'un fichier de seed
409
     *
410
     * @param string $name nom du fichier dont on veut avoir le chemin
411
     */
412
    function seed_path(string $name = ''): string
413
    {
414
        if (! empty($name)) {
415
            $name = ltrim($name, '/\\');
416
        }
417
418
        return DB_SEED_PATH . str_replace('/', DS, $name);
419
    }
420
}
421
422
if (! function_exists('lang_path')) {
423
    /**
424
     * LANG PATH
425
     *
426
     * Renvoie le chemin absolu d'un fichier de langue
427
     *
428
     * @param string $name   nom du fichier dont on veut avoir le chemin
429
     * @param bool   $system specifie s'il s'agit des langues systeme ou applicatif
430
     */
431
    function lang_path(string $name = '', bool $system = false): string
432
    {
433
        if (! empty($name)) {
434
            $name = DS . ltrim($name, '/\\');
435
        }
436
        if ($system === true) {
437
            return SYST_PATH . 'constants' . DS . 'lang' . str_replace('/', DS, $name);
438
        }
439
440
        return RESOURCE_PATH . 'lang' . str_replace('/', DS, $name);
441
    }
442
}
443
444
if (! function_exists('service_path')) {
445
    /**
446
     * SERVICE PATH
447
     *
448
     * Renvoie le chemin absolu d'un service
449
     *
450
     * @param string $name nom du fichier dont on veut avoir le chemin
451
     * @param bool   $only specifie si on veut seulement les services (fichier php ayant le suffixe Service)
452
     */
453
    function service_path(string $name = '', bool $only = true): string
454
    {
455
        if (! empty($name)) {
456
            $name = ltrim($name, '/\\');
457
458
            if ($only === true && ! preg_match('#Service\.php$#', $name)) {
459
                $name = ucfirst($name) . 'Service.php';
460
            }
461
        }
462
463
        return SERVICE_PATH . str_replace('/', DS, $name);
464
    }
465
}
466
467
if (! function_exists('view_path')) {
468
    /**
469
     * VIEW PATH
470
     *
471
     * Renvoie le chemin absolu d'une vue
472
     *
473
     * @param string $name nom du fichier dont on veut avoir le chemin
474
     */
475
    function view_path(string $name = ''): string
476
    {
477
        if (! empty($name)) {
478
            $name = ltrim($name, '/\\');
479
        }
480
481
        return VIEW_PATH . str_replace('/', DS, $name);
482
    }
483
}
484
485
if (! function_exists('layout_path')) {
486
    /**
487
     * LAYOUT PATH
488
     *
489
     * Renvoie le chemin absolu d'un layout
490
     *
491
     * @param string $name nom du fichier dont on veut avoir le chemin
492
     */
493
    function layout_path(string $name = ''): string
494
    {
495
        if (! empty($name)) {
496
            $name = ltrim($name, '/\\');
497
        }
498
499
        return LAYOUT_PATH . str_replace('/', DS, $name);
500
    }
501
}
502
503
if (! function_exists('partial_path')) {
504
    /**
505
     * PARTIAL PATH
506
     *
507
     * Renvoie le chemin absolu d'une partie de vue
508
     *
509
     * @param string $name nom du fichier dont on veut avoir le chemin
510
     */
511
    function partial_path(string $name = ''): string
512
    {
513
        if (! empty($name)) {
514
            $name = DS . ltrim($name, '/\\');
515
        }
516
517
        return VIEW_PATH . 'partials' . str_replace('/', DS, $name);
518
    }
519
}
520
521
if (! function_exists('app_path')) {
522
    /**
523
     * APP PATH
524
     *
525
     * Renvoie le chemin absolu d'un fichier du dossier app
526
     *
527
     * @param string $name nom du fichier dont on veut avoir le chemin
528
     */
529
    function app_path(string $name = ''): string
530
    {
531
        if (! empty($name)) {
532
            $name = ltrim($name, '/\\');
533
        }
534
535
        return APP_PATH . str_replace('/', DS, $name);
536
    }
537
}
538
539
if (! function_exists('cache_path')) {
540
    /**
541
     * CACHE PATH
542
     *
543
     * Renvoie le chemin absolu d'un fichier mis en cache
544
     *
545
     * @param string $name nom du fichier dont on veut avoir le chemin
546
     */
547
    function cache_path(string $name = ''): string
548
    {
549
        if (! empty($name)) {
550
            $name = ltrim($name, '/\\');
551
        }
552
553
        return VIEW_CACHE_PATH . str_replace('/', DS, $name);
554
    }
555
}
556
557
if (! function_exists('dump_path')) {
558
    /**
559
     * DUMP PATH
560
     *
561
     * Renvoie le chemin absolu d'un fichier de sauvegarde (dump) de la base de donnees
562
     *
563
     * @param string $name nom du fichier dont on veut avoir le chemin
564
     */
565
    function dump_path(string $name = ''): string
566
    {
567
        if (! empty($name)) {
568
            $name = ltrim($name, '/\\');
569
        }
570
571
        return DB_DUMP_PATH . str_replace('/', DS, $name);
572
    }
573
}
574
575
if (! function_exists('storage_path')) {
576
    /**
577
     * STORAGE PATH
578
     *
579
     * Renvoie le chemin absolu d'un fichier du dossier storage
580
     *
581
     * @param string $name nom du fichier dont on veut avoir le chemin
582
     */
583
    function storage_path(string $name = ''): string
584
    {
585
        if (! empty($name)) {
586
            $name = ltrim($name, '/\\');
587
        }
588
589
        return STORAGE_PATH . str_replace('/', DS, $name);
590
    }
591
}
592
593
if (! function_exists('css_exist')) {
594
    /**
595
     * CSS EXIST
596
     *
597
     * Verifie si un fichier css ou un sous dossier du repertoire /public/css existe
598
     *
599
     * @param string $name nom du fichier dont on veut verifier
600
     */
601
    function css_exist(string $name = ''): bool
602
    {
603
        return file_exists(css_path($name));
604
    }
605
}
606
607
if (! function_exists('js_exist')) {
608
    /**
609
     * JS EXIST
610
     *
611
     * Verifie si un fichier js ou un sous dossier du repertoire /public/js existe
612
     *
613
     * @param string $name nom du fichier dont on veut verifier
614
     */
615
    function js_exist(string $name = ''): bool
616
    {
617
        return file_exists(js_path($name));
618
    }
619
}
620
621
if (! function_exists('lib_exist')) {
622
    /**
623
     * LIB EXIST
624
     *
625
     * Verifie si un fichier un sous dossier du repertoire /public/lib existe
626
     *
627
     * @param string $name nom du fichier dont on veut verifier
628
     */
629
    function lib_exist(string $name = ''): bool
630
    {
631
        return file_exists(lib_path($name));
632
    }
633
}
634
635
if (! function_exists('less_exist')) {
636
    /**
637
     * LESS EXIST
638
     *
639
     * Verifie si un fichier less ou un sous dossier du repertoire /public/less existe
640
     *
641
     * @param string $name nom du fichier dont on veut verifier
642
     */
643
    function less_exist(string $name = ''): bool
644
    {
645
        return file_exists(less_path($name));
646
    }
647
}
648
649
if (! function_exists('img_exist')) {
650
    /**
651
     * IMG EXIST
652
     *
653
     * Verifie si un fichier ou un sous dossier du repertoire /public/img existe
654
     *
655
     * @param string $name nom du fichier dont on veut verifier
656
     */
657
    function img_exist(string $name = ''): bool
658
    {
659
        return file_exists(img_path($name));
660
    }
661
}
662
663
if (! function_exists('doc_exist')) {
664
    /**
665
     * DOC EXIST
666
     *
667
     * Verifie si un fichier ou un sous dossier du repertoire /public/docs existe
668
     *
669
     * @param string $name nom du fichier dont on veut verifier
670
     */
671
    function doc_exist(string $name = ''): bool
672
    {
673
        return file_exists(docs_path($name));
674
    }
675
}
676
677
if (! function_exists('video_exist')) {
678
    /**
679
     * VIDEO EXIST
680
     *
681
     * Verifie si un fichier ou un sous dossier du repertoire /public/videos existe
682
     *
683
     * @param string $name nom du fichier dont on veut verifier
684
     */
685
    function videos_exist(string $name = ''): bool
686
    {
687
        return file_exists(video_path($name));
688
    }
689
}
690
691
if (! function_exists('public_exist')) {
692
    /**
693
     * PUBLIC EXIST
694
     *
695
     * Verifie si un fichier ou un sous dossier du repertoire /public existe
696
     *
697
     * @param string $name nom du fichier dont on veut verifier
698
     */
699
    function public_exist(string $name = ''): bool
700
    {
701
        return file_exists(public_path($name));
702
    }
703
}
704
705
if (! function_exists('class_exist')) {
706
    /**
707
     * CLASS EXIST
708
     *
709
     * Verifie si un fichier ou un sous dossier du repertoire /app/class existe
710
     *
711
     * @param string $name nom du fichier dont on veut verifier
712
     */
713
    function class_exist(string $name = ''): bool
714
    {
715
        return file_exists(class_path($name));
716
    }
717
}
718
719
if (! function_exists('config_exist')) {
720
    /**
721
     * CONFIG EXIST
722
     *
723
     * Verifie si un fichier ou un sous dossier du repertoire /app/config existe
724
     *
725
     * @param string $name nom du fichier dont on veut verifier
726
     */
727
    function config_exist(string $name = ''): bool
728
    {
729
        return file_exists(config_path($name));
730
    }
731
}
732
733
if (! function_exists('controller_exist')) {
734
    /**
735
     * CONTROLLER EXIST
736
     *
737
     * Verifie si un fichier ou un sous dossier du repertoire /app/controllers existe
738
     *
739
     * @param string $name nom du fichier dont on veut verifier
740
     * @param bool   $only specifie si on veut seulement les contrôleurs (fichiers php ayant le suffixe Controller)
741
     */
742
    function controller_exist(string $name = '', bool $only = true): bool
743
    {
744
        return file_exists(controller_path($name, $only));
745
    }
746
}
747
748
if (! function_exists('entity_exist')) {
749
    /**
750
     * ENTITY EXIST
751
     *
752
     * Verifie si un fichier ou un sous dossier du repertoire /app/entities existe
753
     *
754
     * @param string $name nom du fichier dont on veut verifier
755
     * @param bool   $only specifie si on veut seulement les fichiers d'entité (fichiers php ayant le suffixe Entity)
756
     */
757
    function entity_exist(string $name = '', bool $only = true): bool
758
    {
759
        return file_exists(entity_path($name, $only));
760
    }
761
}
762
763
if (! function_exists('helper_exist')) {
764
    /**
765
     * HELPER EXIST
766
     *
767
     * Verifie si un fichier ou un sous dossier du repertoire /app/helpers ou /system/helpers existe
768
     *
769
     * @param string $name   nom du fichier dont on veut verifier
770
     * @param bool   $system specifie s'il s'agit des helpers systeme ou applicatif
771
     */
772
    function helper_exist(string $name = '', bool $system = false): bool
773
    {
774
        return file_exists(helper_path($name, $system));
775
    }
776
}
777
778
if (! function_exists('library_exist')) {
779
    /**
780
     * LIBRARY EXIST
781
     *
782
     * Verifie si un fichier ou un sous dossier du repertoire /app/libraries ou /system/libraries existe
783
     *
784
     * @param string $name   nom du fichier dont on veut verifier
785
     * @param bool   $system specifie s'il s'agit des librairies systeme ou applicatif
786
     */
787
    function library_exist(string $name = '', bool $system = false): bool
788
    {
789
        return file_exists(library_path($name, $system));
790
    }
791
}
792
793
if (! function_exists('middleware_exist')) {
794
    /**
795
     * MIDDLEWARE EXIST
796
     *
797
     * Verifie si un fichier ou un sous dossier du repertoire /app/middlewares ou /system/middlewares existe
798
     *
799
     * @param string $name   nom du fichier dont on veut verifier
800
     * @param bool   $system specifie s'il s'agit des middlewares systeme ou applicatif
801
     * @param bool   $only   specifie si on veut seulement les middlewares (fichiers php ayant le suffixe Middleware)
802
     */
803
    function middleware_exist(string $name = '', bool $system = false, bool $only = true): bool
804
    {
805
        return file_exists(middleware_path($name, $system, $only));
806
    }
807
}
808
809
if (! function_exists('model_exist')) {
810
    /**
811
     * MODEL EXIST
812
     *
813
     * Verifie si un fichier ou un sous dossier du repertoire /app/models existe
814
     *
815
     * @param string $name nom du fichier dont on veut verifier
816
     * @param bool   $only specifie si on veut seulement les modeles (fichiers php ayant le suffixe Model)
817
     */
818
    function model_exist(string $name = '', bool $only = true): bool
819
    {
820
        return file_exists(model_path($name, $only));
821
    }
822
}
823
824
if (! function_exists('resource_exist')) {
825
    /**
826
     * RESOURCE EXIST
827
     *
828
     * Verifie si un fichier ou un sous dossier du repertoire /app/resources/ existe
829
     *
830
     * @param string $name nom du fichier dont on veut verifier
831
     */
832
    function resource_exist(string $name = ''): bool
833
    {
834
        return file_exists(resource_path($name));
835
    }
836
}
837
838
if (! function_exists('migration_exist')) {
839
    /**
840
     * MIGRATION EXIST
841
     *
842
     * Verifie si un fichier ou un sous dossier du repertoire /app/resources/database/migrations existe
843
     *
844
     * @param string $name nom du fichier dont on veut verifier
845
     */
846
    function migration_exist(string $name = ''): bool
847
    {
848
        return file_exists(migration_path($name));
849
    }
850
}
851
852
if (! function_exists('seed_exist')) {
853
    /**
854
     * SEED EXIST
855
     *
856
     * Verifie si un fichier ou un sous dossier du repertoire /app/resources/database/seeds existe
857
     *
858
     * @param string $name nom du fichier dont on veut verifier
859
     */
860
    function seed_exist(string $name = ''): bool
861
    {
862
        return file_exists(seed_path($name));
863
    }
864
}
865
866
if (! function_exists('lang_exist')) {
867
    /**
868
     * LANG EXIST
869
     *
870
     * Verifie si un fichier ou un sous dossier du repertoire /app/resources/lang ou /system/constants/lang
871
     *
872
     * @param string $name   nom du fichier dont on veut verifier
873
     * @param bool   $system specifie s'il s'agit des langues systeme ou applicatif
874
     */
875
    function lang_exist(string $name = '', bool $system = false): bool
876
    {
877
        return file_exists(lang_path($name, $system));
878
    }
879
}
880
881
if (! function_exists('service_exist')) {
882
    /**
883
     * SERVICE EXIST
884
     *
885
     * Verifie si un fichier ou un sous dossier du repertoire /app/services existe
886
     *
887
     * @param string $name nom du fichier dont on veut verifier
888
     * @param bool   $only specifie si on veut seulement les services (fichier php ayant le suffixe Service)
889
     */
890
    function service_exist(string $name = '', bool $only = true): bool
891
    {
892
        return file_exists(service_path($name, $only));
893
    }
894
}
895
896
if (! function_exists('view_exist')) {
897
    /**
898
     * VIEW EXIST
899
     *
900
     * Verifie si un fichier ou un sous dossier du repertoire /app/views existe
901
     *
902
     * @param string $name nom du fichier dont on veut verifier
903
     */
904
    function view_exist(string $name = ''): bool
905
    {
906
        return file_exists(view_path($name));
907
    }
908
}
909
910
if (! function_exists('layout_exist')) {
911
    /**
912
     * LAYOUT EXIST
913
     *
914
     * Verifie si un fichier ou un sous dossier du repertoire /app/views/layouts existe
915
     *
916
     * @param string $name nom du fichier dont on veut verifier
917
     */
918
    function layout_exist(string $name = ''): bool
919
    {
920
        return file_exists(layout_path($name));
921
    }
922
}
923
924
if (! function_exists('partial_exist')) {
925
    /**
926
     * PARTIAL EXIST
927
     *
928
     * Verifie si un fichier ou un sous dossier du repertoire /app/views/partials existe
929
     *
930
     * @param string $name nom du fichier dont on veut verifier
931
     */
932
    function partial_exist(string $name = ''): bool
933
    {
934
        return file_exists(partial_path($name));
935
    }
936
}
937
938
if (! function_exists('app_exist')) {
939
    /**
940
     * APP EXIST
941
     *
942
     * Verifie si un fichier ou un sous dossier du repertoire /app/ existe
943
     *
944
     * @param string $name nom du fichier dont on veut verifier
945
     */
946
    function app_exist(string $name = ''): bool
947
    {
948
        return file_exists(app_path($name));
949
    }
950
}
951
952
if (! function_exists('cache_exist')) {
953
    /**
954
     * CACHE EXIST
955
     *
956
     * Verifie si un fichier ou un sous dossier du repertoire /storage/cache existe
957
     *
958
     * @param string $name nom du fichier dont on veut verifier
959
     */
960
    function cache_exist(string $name = ''): bool
961
    {
962
        return file_exists(cache_path($name));
963
    }
964
}
965
966
if (! function_exists('dump_exist')) {
967
    /**
968
     * DUMP EXIST
969
     *
970
     * Verifie si un fichier ou un sous dossier du repertoire /storage/database/dump existe
971
     *
972
     * @param string $name nom du fichier dont on veut verifier
973
     */
974
    function dump_exist(string $name = ''): bool
975
    {
976
        return file_exists(dump_path($name));
977
    }
978
}
979
980
if (! function_exists('storage_exist')) {
981
    /**
982
     * STORAGE EXIST
983
     *
984
     * Verifie si un fichier ou un sous dossier du repertoire /storage existe
985
     *
986
     * @param string $name nom du fichier dont on veut verifier
987
     */
988
    function storage_exist(string $name = ''): bool
989
    {
990
        return file_exists(storage_path($name));
991
    }
992
}
993
994
if (! function_exists('include_config')) {
995
    /**
996
     * INCLUDE CONFIG
997
     *
998
     * inclus un fichier de configuration
999
     *
1000
     * @param string $name     nom du fichier dont on veut inclure
1001
     * @param array  $data     les données à transferer dans le fichier inclus
1002
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1003
     *
1004
     * @return void
1005
     */
1006
    function include_config(string $name, array $data = [], bool $required = true)
1007
    {
1008
        _include_path(config_path($name), $data, $required);
1009
    }
1010
}
1011
1012
if (! function_exists('include_controller')) {
1013
    /**
1014
     * INCLUDE CONTROLLER
1015
     *
1016
     * inclus un contrôleur
1017
     *
1018
     * @param string $name     nom du fichier dont on veut inclure
1019
     * @param array  $data     les données à transferer dans le fichier inclus
1020
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1021
     * @param bool   $only     specifie si on veut seulement les contrôleurs (fichier php ayant le suffixe Controller)
1022
     *
1023
     * @return void
1024
     */
1025
    function include_controller(string $name, array $data = [], bool $required = true, bool $only = true)
1026
    {
1027
        _include_path(controller_path($name, $only), $data, $required);
1028
    }
1029
}
1030
1031
if (! function_exists('include_class')) {
1032
    /**
1033
     * INCLUDE CLASS
1034
     *
1035
     * inclus une classe applicative
1036
     *
1037
     * @param string $name     nom du fichier dont on veut inclure
1038
     * @param array  $data     les données à transferer dans le fichier inclus
1039
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1040
     *
1041
     * @return void
1042
     */
1043
    function include_class(string $name, array $data = [], bool $required = true)
1044
    {
1045
        _include_path(class_path($name), $data, $required);
1046
    }
1047
}
1048
1049
if (! function_exists('include_entity')) {
1050
    /**
1051
     * INCLUDE ENTITY
1052
     *
1053
     * inclus une entité
1054
     *
1055
     * @param string $name     nom du fichier dont on veut inclure
1056
     * @param array  $data     les données à transferer dans le fichier inclus
1057
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1058
     * @param bool   $only     specifie si on veut seulement les entités (fichier php ayant le suffixe Entity)
1059
     *
1060
     * @return void
1061
     */
1062
    function include_entity(string $name, array $data = [], bool $required = true, bool $only = true)
1063
    {
1064
        _include_path(entity_path($name, $only), $data, $required);
1065
    }
1066
}
1067
1068
if (! function_exists('include_helper')) {
1069
    /**
1070
     * INCLUDE HELPER
1071
     *
1072
     * inclus un helper
1073
     *
1074
     * @param string $name     nom du fichier dont on veut inclure
1075
     * @param array  $data     les données à transferer dans le fichier inclus
1076
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1077
     *
1078
     * @return void
1079
     */
1080
    function include_helper(string $name, array $data = [], bool $required = true)
1081
    {
1082
        _include_path(helper_path($name), $data, $required);
1083
    }
1084
}
1085
1086
if (! function_exists('include_library')) {
1087
    /**
1088
     * INCLUDE LIBRARY
1089
     *
1090
     * inclus une librarie
1091
     *
1092
     * @param string $name     nom du fichier dont on veut inclure
1093
     * @param array  $data     les données à transferer dans le fichier inclus
1094
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1095
     * @param bool   $system   specifie s'il s'agit des librairies systeme ou applicatif
1096
     *
1097
     * @return void
1098
     */
1099
    function include_library(string $name, array $data = [], bool $required = true, bool $system = false)
1100
    {
1101
        _include_path(library_path($name, $system), $data, $required);
1102
    }
1103
}
1104
1105
if (! function_exists('include_middleware')) {
1106
    /**
1107
     * INCLUDE MIDDLEWARE
1108
     *
1109
     * inclus un middleware
1110
     *
1111
     * @param string $name     nom du fichier dont on veut inclure
1112
     * @param array  $data     les données à transferer dans le fichier inclus
1113
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1114
     * @param bool   $system   specifie s'il s'agit des middlewares systeme ou applicatif
1115
     * @param bool   $only     specifie si on veut seulement les middlewares (fichiers php ayant le suffixe Middleware)
1116
     *
1117
     * @return void
1118
     */
1119
    function include_middleware(string $name, array $data = [], bool $required = true, bool $system = false, bool $only = true)
1120
    {
1121
        _include_path(middleware_path($name, $system, $only), $data, $required);
1122
    }
1123
}
1124
1125
if (! function_exists('include_model')) {
1126
    /**
1127
     * INCLUDE MODEL
1128
     *
1129
     * inclus un modeèle
1130
     *
1131
     * @param string $name     nom du fichier dont on veut inclure
1132
     * @param array  $data     les données à transferer dans le fichier inclus
1133
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1134
     * @param bool   $only     specifie si on veut seulement les modèles (fichier php ayant le suffixe Model)
1135
     *
1136
     * @return void
1137
     */
1138
    function include_model(string $name, array $data = [], bool $required = true, bool $only = true)
1139
    {
1140
        _include_path(model_path($name, $only), $data, $required);
1141
    }
1142
}
1143
1144
if (! function_exists('include_resource')) {
1145
    /**
1146
     * INCLUDE RESOURCE
1147
     *
1148
     * inclus un fichier resource
1149
     *
1150
     * @param string $name     nom du fichier dont on veut inclure
1151
     * @param array  $data     les données à transferer dans le fichier inclus
1152
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1153
     *
1154
     * @return void
1155
     */
1156
    function include_resource(string $name, array $data = [], bool $required = true)
1157
    {
1158
        _include_path(resource_path($name), $data, $required);
1159
    }
1160
}
1161
1162
if (! function_exists('include_service')) {
1163
    /**
1164
     * INCLUDE SERVICE
1165
     *
1166
     * inclus un service
1167
     *
1168
     * @param string $name     nom du fichier dont on veut inclure
1169
     * @param array  $data     les données à transferer dans le fichier inclus
1170
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1171
     * @param bool   $only     specifie si on veut seulement les services (fichier php ayant le suffixe Service)
1172
     *
1173
     * @return void
1174
     */
1175
    function include_service(string $name, array $data = [], bool $required = true, bool $only = true)
1176
    {
1177
        _include_path(service_path($name, $only), $data, $required);
1178
    }
1179
}
1180
1181
if (! function_exists('include_view')) {
1182
    /**
1183
     * INCLUDE VIEW
1184
     *
1185
     * inclus une vue
1186
     *
1187
     * @param string $name     nom du fichier dont on veut inclure
1188
     * @param array  $data     les données à transferer dans le fichier inclus
1189
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1190
     *
1191
     * @return void
1192
     */
1193
    function include_view(string $name, array $data = [], bool $required = true)
1194
    {
1195
        _include_path(view_path($name), $data, $required);
1196
    }
1197
}
1198
1199
if (! function_exists('include_layout')) {
1200
    /**
1201
     * INCLUDE LAYOUT
1202
     *
1203
     * inclus un template de vue
1204
     *
1205
     * @param string $name     nom du fichier dont on veut inclure
1206
     * @param array  $data     les données à transferer dans le fichier inclus
1207
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1208
     *
1209
     * @return void
1210
     */
1211
    function include_layout(string $name, array $data = [], bool $required = true)
1212
    {
1213
        _include_path(layout_path($name), $data, $required);
1214
    }
1215
}
1216
1217
if (! function_exists('include_partial')) {
1218
    /**
1219
     * INCLUDE PARTIAL
1220
     *
1221
     * inclus une partie de vue
1222
     *
1223
     * @param string $name     nom du fichier dont on veut inclure
1224
     * @param array  $data     les données à transferer dans le fichier inclus
1225
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1226
     *
1227
     * @return void
1228
     */
1229
    function include_partial(string $name, array $data = [], bool $required = true)
1230
    {
1231
        _include_path(partial_path($name), $data, $required);
1232
    }
1233
}
1234
1235
if (! function_exists('_include_path')) {
1236
    /**
1237
     * inclus un fichier
1238
     *
1239
     * @param string $path     chemin du fichier dont on veut inclure
1240
     * @param array  $data     les données à transferer dans le fichier inclus
1241
     * @param bool   $required specifie si le fichier est obligatoire ou pas
1242
     *
1243
     * @return void
1244
     */
1245
    function _include_path(string $path, array $data = [], bool $required = true)
1246
    {
1247
        if (file_exists($path)) {
1248
            extract($data);
1249
            require_once $path;
1250
        } elseif (true === $required) {
1251
            throw new Exception("The file '{$path}' does not exist");
1252
        }
1253
    }
1254
}
1255