-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhelpers.php
More file actions
1800 lines (1624 loc) · 44.6 KB
/
Copy pathhelpers.php
File metadata and controls
1800 lines (1624 loc) · 44.6 KB
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
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
use Bow\Auth\Auth;
use Bow\Auth\Exception\AuthenticationException;
use Bow\Auth\Guards\GuardContract;
use Bow\Cache\Cache;
use Bow\Configuration\Loader;
use Bow\Container\Capsule;
use Bow\Database\Barry\Model;
use Bow\Database\Database as DB;
use Bow\Database\Exception\ConnectionException;
use Bow\Database\QueryBuilder;
use Bow\Event\Event;
use Bow\Http\Exception\HttpException;
use Bow\Http\HttpStatus;
use Bow\Http\Redirect;
use Bow\Http\Request;
use Bow\Http\Response;
use Bow\Mail\Contracts\MailAdapterInterface;
use Bow\Mail\Mail;
use Bow\Queue\QueueTask;
use Bow\Security\Crypto;
use Bow\Security\Hash;
use Bow\Security\Sanitize;
use Bow\Security\Tokenize;
use Bow\Session\Cookie;
use Bow\Session\Exception\SessionException;
use Bow\Session\Session;
use Bow\Storage\Exception\DiskNotFoundException;
use Bow\Storage\Exception\ServiceConfigurationNotFoundException;
use Bow\Storage\Exception\ServiceNotFoundException;
use Bow\Storage\Service\DiskFilesystemService;
use Bow\Storage\Service\FTPService;
use Bow\Storage\Service\S3Service;
use Bow\Storage\Storage;
use Bow\Support\Collection;
use Bow\Support\Env;
use Bow\Support\Str;
use Bow\Support\Util;
use Bow\Translate\Translator;
use Bow\Validation\Validate;
use Bow\Validation\Validator;
use Bow\View\View;
use Carbon\Carbon;
use Monolog\Logger;
/*
* Global helper functions.
*
* Each helper is wrapped in `if (!function_exists(...))` so an application may
* override any of them by declaring its own version before this file loads.
* Most helpers are thin shortcuts over a framework class; the section banners
* below mark where each topic begins.
*/
if (!function_exists('app')) {
/**
* Resolve the service container, or a binding out of it.
*
* With no arguments the container instance itself is returned; with a key
* the matching binding is resolved (using `$setting` as constructor
* parameters when provided).
*
* @param ?string $key Binding name to resolve, or null for the container
* @param array $setting Parameters passed to makeWith() when resolving
* @return mixed
*/
function app(?string $key = null, array $setting = []): mixed
{
$capsule = Capsule::getInstance();
if ($key == null && $setting == null) {
return $capsule;
}
// No extra parameters: a plain resolution is enough.
if (empty($setting)) {
return $capsule->make($key);
}
return $capsule->makeWith($key, $setting);
}
}
if (!function_exists('config')) {
/**
* Read or write application configuration.
*
* No key returns the configuration loader; a key alone reads the value;
* a key with a value writes (and returns) it.
*
* @param string|null $key Dotted configuration key
* @param mixed $setting Value to set, or null to read
* @return Loader|mixed
* @throws Exception
*/
function config(?string $key = null, mixed $setting = null): mixed
{
$config = Loader::getInstance();
if (is_null($key)) {
return $config;
}
if (is_null($setting)) {
return $config[$key];
}
return $config[$key] = $setting;
}
}
if (!function_exists('response')) {
/**
* Get the shared Response instance from the container.
*
* @return Response
*/
function response(): Response
{
/**
* @var Response $response
*/
$response = app('response');
return $response;
}
}
if (!function_exists('request')) {
/**
* Get the shared Request instance from the container.
*
* @return Request
*/
function request(): Request
{
/**
* @var Request $request
*/
$request = app('request');
return $request;
}
}
if (!function_exists('db')) {
/**
* Get the database manager, optionally on another connection.
*
* With no arguments the current connection is returned. When `$cb` is
* given it runs against `$name`, then the previous connection is restored.
*
* Note: registered under the `db` guard but the function is named
* `app_db()`; call it as `app_db(...)`.
*
* @param string|null $name Connection name to switch to
* @param callable|null $cb Work to run on that connection, then revert
* @return DB
* @throws ConnectionException
*/
function app_db(?string $name = null, ?callable $cb = null): DB
{
if (func_num_args() == 0) {
return DB::getInstance();
}
$old_connection = DB::getConnectionName();
if ($old_connection === $name) {
$instance = DB::getInstance();
} else {
$instance = DB::connection($name);
}
// When callback is defined, we execute the callback
// set the old connection name after execution
if (is_callable($cb)) {
$cb();
$instance = DB::connection($old_connection);
}
return $instance;
}
}
if (!function_exists('view')) {
/**
* Render a view template through View::parse().
*
* `$data` may be passed as the status code directly (e.g. `view('404', 404)`),
* in which case it is treated as `$code` and the data set is left empty.
*
* @param string $template View name
* @param array|int $data View data, or the HTTP status code
* @param int $code HTTP status code
* @return View
*/
function view(string $template, int|array $data = [], int $code = 200): View
{
// Allow the status code to be supplied in the $data slot.
if (is_int($data)) {
$code = $data;
$data = [];
}
response()
->status($code);
return View::parse($template, $data);
}
}
if (!function_exists('table')) {
/**
* Get a query builder for a table (optionally on another connection).
*
* @param string $name Table name
* @param ?string $connexion Connection to switch to first
* @return QueryBuilder
* @throws ConnectionException
* @deprecated Use app_db_table() instead.
* @see app_db_table()
*/
function table(string $name, ?string $connexion = null): QueryBuilder
{
if (is_string($connexion)) {
app_db($connexion);
}
return DB::table($name);
}
}
if (!function_exists('app_db_table')) {
/**
* Get a query builder for a table (optionally on another connection).
*
* @param string $name Table name
* @param ?string $connexion Connection to switch to first
* @return QueryBuilder
* @throws ConnectionException
*/
function app_db_table(string $name, ?string $connexion = null): QueryBuilder
{
if (is_string($connexion)) {
app_db($connexion);
}
return DB::table($name);
}
}
if (!function_exists('get_last_insert_id')) {
/**
* Returns the last ID following an INSERT query
* on a table whose ID is auto_increment.
*
* @param string|null $name Sequence/connection name, if required
* @return int
*/
function get_last_insert_id(?string $name = null): int
{
return DB::lastInsertId($name);
}
}
if (!function_exists('app_db_select')) {
/**
* Run a raw SELECT query.
*
* app_db_select('SELECT * FROM users');
*
* @param string $sql SQL statement, may contain bindings
* @param array $data Values bound to the statement
* @return int|array|stdClass
*/
function app_db_select(string $sql, array $data = []): array|int|stdClass
{
return DB::select($sql, $data);
}
}
if (!function_exists('app_db_select_one')) {
/**
* Run a raw SELECT query and return a single row.
*
* @param string $sql SQL statement, may contain bindings
* @param array $data Values bound to the statement
* @return int|array|StdClass
*/
function app_db_select_one(string $sql, array $data = []): array|int|StdClass
{
return DB::selectOne($sql, $data);
}
}
if (!function_exists('app_db_insert')) {
/**
* Run a raw INSERT query.
*
* @param string $sql SQL statement, may contain bindings
* @param array $data Values bound to the statement
* @return int Number of affected rows
*/
function app_db_insert(string $sql, array $data = []): int
{
return DB::insert($sql, $data);
}
}
if (!function_exists('app_db_delete')) {
/**
* Run a raw DELETE query.
*
* @param string $sql SQL statement, may contain bindings
* @param array $data Values bound to the statement
* @return int Number of affected rows
*/
function app_db_delete(string $sql, array $data = []): int
{
return DB::delete($sql, $data);
}
}
if (!function_exists('app_db_update')) {
/**
* Run a raw UPDATE query.
*
* @param string $sql SQL statement, may contain bindings
* @param array $data Values bound to the statement
* @return int Number of affected rows
*/
function app_db_update(string $sql, array $data = []): int
{
return DB::update($sql, $data);
}
}
if (!function_exists('app_db_statement')) {
/**
* Run a schema/DDL statement (CREATE, ALTER, RENAME, DROP, ...).
*
* @param string $sql SQL statement
* @return int
*/
function app_db_statement(string $sql): int
{
return DB::statement($sql);
}
}
if (!function_exists('debug')) {
/**
* Dump one or more variables with colourised, typed output.
*
* Accepts any number of arguments; each is sanitised then handed to
* Util::debug().
*
* @return void
*/
function debug(): void
{
array_map(
function ($x) {
call_user_func_array([Util::class, 'debug'], [$x]);
},
secure(func_get_args())
);
}
}
if (!function_exists("sep")) {
/**
* Get the OS-specific directory separator.
*
* @return string
*/
function sep(): string
{
return call_user_func([Util::class, 'sep']);
}
}
if (!function_exists('create_csrf_token')) {
/**
* Create (or fetch) the current CSRF token payload.
*
* @param int|null $time Lifetime in seconds for the generated token
* @return ?array The token data (token, field, expire_at), or null
* @throws SessionException
*/
function create_csrf_token(?int $time = null): ?array
{
return Tokenize::csrf($time);
}
}
if (!function_exists('csrf_token')) {
/**
* Get the current CSRF token string.
*
* @return string
* @throws HttpException When no token could be generated
* @throws SessionException
*/
function csrf_token(): string
{
$csrf = (array) create_csrf_token();
if (count($csrf) == 0) {
throw new HttpException(
"CSRF token is not generated",
500
);
}
return $csrf['token'];
}
}
if (!function_exists('csrf_field')) {
/**
* Get the ready-made hidden CSRF input field.
*
* @return string
* @throws HttpException When no token could be generated
* @throws SessionException
*/
function csrf_field(): string
{
$csrf = (array) create_csrf_token();
if (count($csrf) == 0) {
throw new HttpException(
"CSRF token is not generated",
500
);
}
return $csrf['field'];
}
}
if (!function_exists('method_field')) {
/**
* Build a hidden input that spoofs the HTTP method (PUT, PATCH, DELETE).
*
* @param string $method HTTP verb to spoof
* @return string
*/
function method_field(string $method): string
{
$method = strtoupper($method);
return '<input type="hidden" name="_method" value="' . $method . '">';
}
}
if (!function_exists('gen_csrf_token')) {
/**
* Generate a fresh, standalone token string (not stored in the session).
*
* @return string
*/
function gen_csrf_token(): string
{
return Tokenize::make();
}
}
if (!function_exists('verify_csrf')) {
/**
* Verify a submitted CSRF token against the stored one.
*
* @param string $token Token received from the request
* @param bool $strict Also enforce token expiry when true
* @return bool
* @throws SessionException
*/
function verify_csrf(string $token, bool $strict = false): bool
{
return Tokenize::verify($token, $strict);
}
}
if (!function_exists('csrf_time_is_expired')) {
/**
* Check whether the stored CSRF token has expired.
*
* @param string|null $time Reference time, defaults to now
* @return bool
* @throws SessionException
*/
function csrf_time_is_expired(?string $time = null): bool
{
return Tokenize::csrfExpired($time);
}
}
if (!function_exists('response_json')) {
/**
* Send a JSON response.
*
* @param array|object $data Payload to encode
* @param int $code HTTP status code
* @param array $headers Extra response headers
* @return string
*/
function response_json(array|object $data, int $code = 200, array $headers = []): string
{
return response()->json($data, $code, $headers);
}
}
if (!function_exists('response_download')) {
/**
* Send a file as a download response.
*
* @param string $file Path to the file on disk
* @param null|string $filename Name presented to the client
* @param array $headers Extra response headers
* @return string
*/
function response_download(string $file, ?string $filename = null, array $headers = []): string
{
return response()->download($file, $filename, $headers);
}
}
if (!function_exists('set_response_status_code')) {
/**
* Set the HTTP response status code.
*
* @param int $code
* @return mixed
*/
function set_response_status_code(int $code): mixed
{
return response()->status($code);
}
}
if (!function_exists('sanitize')) {
/**
* Sanitize a value (numeric values are returned untouched).
*
* @param mixed $data
* @return mixed
*/
function sanitize(mixed $data): mixed
{
if (is_numeric($data)) {
return $data;
}
return Sanitize::make($data);
}
}
if (!function_exists('secure')) {
/**
* Sanitize a value in strict/secure mode (numeric values pass through).
*
* @param mixed $data
* @return mixed
*/
function secure(mixed $data): mixed
{
if (is_numeric($data)) {
return $data;
}
return Sanitize::make($data, true);
}
}
if (!function_exists('set_response_header')) {
/**
* Add a header to the outgoing response.
*
* @param string $key
* @param string $value
* @return void
*/
function set_response_header(string $key, string $value): void
{
response()->withHeader($key, $value);
}
}
if (!function_exists('get_response_header')) {
/**
* Read a header from the incoming request.
*
* @param string $key
* @return string|null
*/
function get_response_header(string $key): ?string
{
return request()->getHeader($key);
}
}
if (!function_exists('redirect')) {
/**
* Get the redirector, optionally redirecting straight to a path.
*
* @param string|null $path Target to redirect to, or null for the instance
* @return Redirect
*/
function redirect(?string $path = null): Redirect
{
$redirect = Redirect::getInstance();
if ($path !== null) {
$redirect->to($path);
}
return $redirect;
}
}
if (!function_exists('url')) {
/**
* Build an absolute URL from the current request base.
*
* Passing an array as the first argument is treated as the query string
* parameters (the path is then the current URL).
*
* @param string|array $url Path to append, or query parameters
* @param array $parameters Query string parameters
* @return string
*/
function url(string|array $url = '', array $parameters = []): string
{
$current = trim(request()->url(), '/');
// First argument given as parameters: keep the current path.
if (is_array($url)) {
$parameters = $url;
$url = '';
}
if (is_string($url)) {
$current .= '/' . trim($url, '/');
}
if (count($parameters) > 0) {
$current .= '?' . http_build_query($parameters);
}
return $current;
}
}
if (!function_exists('pdo')) {
/**
* Get the underlying PDO instance.
*
* @return PDO
*/
function pdo(): PDO
{
return DB::getPdo();
}
}
if (!function_exists('set_pdo')) {
/**
* Replace the underlying PDO instance.
*
* @param PDO $pdo
* @return PDO The newly set instance
*/
function set_pdo(PDO $pdo): PDO
{
DB::setPdo($pdo);
return pdo();
}
}
if (!function_exists('collect')) {
/**
* Wrap an array in a Collection.
*
* @param array $data
* @return Collection
*/
function collect(array $data = []): Collection
{
return new Collection($data);
}
}
if (!function_exists('encrypt')) {
/**
* Encrypt data using the application security key.
*
* Returns an authenticated payload (random IV + HMAC), so encrypting the
* same value twice yields different ciphertexts.
*
* @param string $data
* @return string
*/
function encrypt(string $data): string
{
return Crypto::encrypt($data);
}
}
if (!function_exists('decrypt')) {
/**
* Decrypt a value previously produced by encrypt().
*
* Fails closed: returns false when the payload has been tampered with or
* was encrypted with a different key.
*
* @param string $data
* @return string|bool
*/
function decrypt(string $data): string|bool
{
return Crypto::decrypt($data);
}
}
// ===== Database: transactions =====
if (!function_exists('app_db_transaction')) {
/**
* Begin a database transaction.
*
* @return void
*/
function app_db_transaction(): void
{
DB::startTransaction();
}
}
if (!function_exists('app_db_transaction_started')) {
/**
* Check whether a database transaction is currently open.
*
* @return bool
*/
function app_db_transaction_started(): bool
{
return DB::inTransaction();
}
}
if (!function_exists('app_db_rollback')) {
/**
* Roll back the current database transaction.
*
* @return void
*/
function app_db_rollback(): void
{
DB::rollback();
}
}
if (!function_exists('app_db_commit')) {
/**
* Commit the current database transaction.
*
* @return void
*/
function app_db_commit(): void
{
DB::commit();
}
}
if (!function_exists('event')) {
/**
* Get the event dispatcher, or emit an event.
*
* Called with no arguments it returns the dispatcher; otherwise the first
* argument is the event name and the rest are passed to its listeners.
*
* @param mixed ...$args Event name followed by its payload
* @return mixed
*/
function event(): mixed
{
$args = func_get_args();
$event = Event::getInstance();
if (count($args) === 0) {
return $event;
}
return call_user_func_array([$event, "emit"], $args);
}
}
if (!function_exists('app_event')) {
/**
* Get the event dispatcher, or emit an event.
*
* @param mixed ...$args Event name followed by its payload
* @return mixed
* @see event() Identical behaviour; event() is the preferred name.
*/
function app_event(): mixed
{
$args = func_get_args();
$event = Event::getInstance();
if (count($args) === 0) {
return $event;
}
return call_user_func_array([$event, "emit"], $args);
}
}
if (!function_exists('flash')) {
/**
* Store a one-request flash message in the session.
*
* @param string $key Flash key
* @param string $message Message to store
* @return mixed
* @throws SessionException
*/
function flash(string $key, string $message): mixed
{
return Session::getInstance()
->flash($key, $message);
}
}
if (!function_exists('app_flash')) {
/**
* Store a one-request flash message in the session.
*
* @param string $key Flash key
* @param string $message Message to store
* @return mixed
* @throws SessionException
* @see flash() Identical behaviour; flash() is the preferred name.
*/
function app_flash(string $key, string $message): mixed
{
return Session::getInstance()
->flash($key, $message);
}
}
if (!function_exists('email')) {
/**
* Send an email, or get the mailer instance.
*
* With no view the mailer instance is returned; otherwise the view is
* rendered and sent.
*
* @param null|string $view View name for the message body
* @param array $data Data bound to the view
* @param callable|null $cb Builder callback to configure the message
* @return MailAdapterInterface|bool
*/
function email(
?string $view = null,
?array $data = [],
?callable $cb = null
): MailAdapterInterface|bool {
if ($view === null) {
return Mail::getInstance();
}
return Mail::send($view, $data, $cb);
}
}
if (!function_exists('app_email')) {
/**
* Send an email, or get the mailer instance.
*
* @param null|string $view View name for the message body
* @param array $data Data bound to the view
* @param callable|null $cb Builder callback to configure the message
* @return MailAdapterInterface|bool
* @see email() Identical behaviour; email() is the preferred name.
*/
function app_email(
?string $view = null,
?array $data = [],
?callable $cb = null
): MailAdapterInterface|bool {
if ($view === null) {
return Mail::getInstance();
}
return Mail::send($view, $data, $cb);
}
}
if (!function_exists('raw_email')) {
/**
* Send a plain (non-templated) email.
*
* @param string $to Recipient address
* @param string $subject Subject line
* @param string $message Message body
* @param array $headers Extra mail headers
* @return bool
*/
function raw_email(string $to, string $subject, string $message, array $headers = []): bool
{
return Mail::raw($to, $subject, $message, $headers);
}
}
if (!function_exists('session')) {
/**
* Get the session manager, or read a session value.
*
* @param string|null $key Key to read, or null for the manager
* @param mixed $default Value returned when the key is absent
* @return mixed
* @throws SessionException
*/
function session(?string $key = null, mixed $default = null): mixed
{
if ($key == null) {
return Session::getInstance();
}
return Session::getInstance()->get($key, $default);
}
}
if (!function_exists('cookie')) {
/**
* Read or write cookies.
*
* No key returns all cookies; a key alone reads one; a key with data
* writes it.
*
* @param string|null $key Cookie name
* @param mixed $data Value to write, or null to read
* @param int $expiration Lifetime in seconds when writing
* @return string|array|object|null
*/
function cookie(
?string $key = null,
mixed $data = null,
int $expiration = 3600
): string|array|object|null {
if ($key === null) {
return Cookie::all();
}
if ($data == null) {
return Cookie::get($key);
}
return Cookie::set($key, $data, $expiration);
}
}
if (!function_exists('validator')) {
/**
* Validate input against a set of rules.
*
* @param array $inputs Data to validate
* @param array $rules Validation rules keyed by field
* @param array $messages Custom error messages
* @return Validate
*/
function validator(array $inputs, array $rules, array $messages = []): Validate
{
return Validator::make($inputs, $rules, $messages);
}
}
if (!function_exists('route')) {
/**
* Build a URL for a named route.
*
* Named placeholders in the route are filled from `$data`; leftover
* entries become the query string. Passing a bool as `$data` is treated
* as the `$absolute` flag.
*
* @param string $name Route name
* @param bool|array $data Placeholder values, or the absolute flag
* @param bool $absolute Prefix with APP_URL when true
* @return string
* @throws InvalidArgumentException When the route or a placeholder is missing
*/