Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
use Illuminate\Container\Container;
4
use Illuminate\Contracts\Auth\Access\Gate;
5
use Illuminate\Contracts\Auth\Factory as AuthFactory;
6
use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory;
7
use Illuminate\Contracts\Bus\Dispatcher;
8
use Illuminate\Contracts\Cookie\Factory as CookieFactory;
9
use Illuminate\Contracts\Debug\ExceptionHandler;
10
use Illuminate\Contracts\Routing\ResponseFactory;
11
use Illuminate\Contracts\Routing\UrlGenerator;
12
use Illuminate\Contracts\Support\Responsable;
13
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
14
use Illuminate\Contracts\View\Factory as ViewFactory;
15
use Illuminate\Foundation\Bus\PendingClosureDispatch;
16
use Illuminate\Foundation\Bus\PendingDispatch;
17
use Illuminate\Foundation\Mix;
18
use Illuminate\Http\Exceptions\HttpResponseException;
19
use Illuminate\Queue\CallQueuedClosure;
20
use Illuminate\Routing\Router;
21
use Illuminate\Support\Facades\Date;
22
use Illuminate\Support\HtmlString;
23
use Symfony\Component\HttpFoundation\Response;
24
 
25
if (! function_exists('abort')) {
26
    /**
27
     * Throw an HttpException with the given data.
28
     *
29
     * @param  \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int  $code
30
     * @param  string  $message
31
     * @param  array  $headers
32
     * @return never
33
     *
34
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
35
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
36
     */
37
    function abort($code, $message = '', array $headers = [])
38
    {
39
        if ($code instanceof Response) {
40
            throw new HttpResponseException($code);
41
        } elseif ($code instanceof Responsable) {
42
            throw new HttpResponseException($code->toResponse(request()));
43
        }
44
 
45
        app()->abort($code, $message, $headers);
46
    }
47
}
48
 
49
if (! function_exists('abort_if')) {
50
    /**
51
     * Throw an HttpException with the given data if the given condition is true.
52
     *
53
     * @param  bool  $boolean
54
     * @param  \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int  $code
55
     * @param  string  $message
56
     * @param  array  $headers
57
     * @return void
58
     *
59
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
60
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
61
     */
62
    function abort_if($boolean, $code, $message = '', array $headers = [])
63
    {
64
        if ($boolean) {
65
            abort($code, $message, $headers);
66
        }
67
    }
68
}
69
 
70
if (! function_exists('abort_unless')) {
71
    /**
72
     * Throw an HttpException with the given data unless the given condition is true.
73
     *
74
     * @param  bool  $boolean
75
     * @param  \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Support\Responsable|int  $code
76
     * @param  string  $message
77
     * @param  array  $headers
78
     * @return void
79
     *
80
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
81
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
82
     */
83
    function abort_unless($boolean, $code, $message = '', array $headers = [])
84
    {
85
        if (! $boolean) {
86
            abort($code, $message, $headers);
87
        }
88
    }
89
}
90
 
91
if (! function_exists('action')) {
92
    /**
93
     * Generate the URL to a controller action.
94
     *
95
     * @param  string|array  $name
96
     * @param  mixed  $parameters
97
     * @param  bool  $absolute
98
     * @return string
99
     */
100
    function action($name, $parameters = [], $absolute = true)
101
    {
102
        return app('url')->action($name, $parameters, $absolute);
103
    }
104
}
105
 
106
if (! function_exists('app')) {
107
    /**
108
     * Get the available container instance.
109
     *
110
     * @param  string|null  $abstract
111
     * @param  array  $parameters
112
     * @return mixed|\Illuminate\Contracts\Foundation\Application
113
     */
114
    function app($abstract = null, array $parameters = [])
115
    {
116
        if (is_null($abstract)) {
117
            return Container::getInstance();
118
        }
119
 
120
        return Container::getInstance()->make($abstract, $parameters);
121
    }
122
}
123
 
124
if (! function_exists('app_path')) {
125
    /**
126
     * Get the path to the application folder.
127
     *
128
     * @param  string  $path
129
     * @return string
130
     */
131
    function app_path($path = '')
132
    {
133
        return app()->path($path);
134
    }
135
}
136
 
137
if (! function_exists('asset')) {
138
    /**
139
     * Generate an asset path for the application.
140
     *
141
     * @param  string  $path
142
     * @param  bool|null  $secure
143
     * @return string
144
     */
145
    function asset($path, $secure = null)
146
    {
147
        return app('url')->asset($path, $secure);
148
    }
149
}
150
 
151
if (! function_exists('auth')) {
152
    /**
153
     * Get the available auth instance.
154
     *
155
     * @param  string|null  $guard
156
     * @return \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\Guard|\Illuminate\Contracts\Auth\StatefulGuard
157
     */
158
    function auth($guard = null)
159
    {
160
        if (is_null($guard)) {
161
            return app(AuthFactory::class);
162
        }
163
 
164
        return app(AuthFactory::class)->guard($guard);
165
    }
166
}
167
 
168
if (! function_exists('back')) {
169
    /**
170
     * Create a new redirect response to the previous location.
171
     *
172
     * @param  int  $status
173
     * @param  array  $headers
174
     * @param  mixed  $fallback
175
     * @return \Illuminate\Http\RedirectResponse
176
     */
177
    function back($status = 302, $headers = [], $fallback = false)
178
    {
179
        return app('redirect')->back($status, $headers, $fallback);
180
    }
181
}
182
 
183
if (! function_exists('base_path')) {
184
    /**
185
     * Get the path to the base of the install.
186
     *
187
     * @param  string  $path
188
     * @return string
189
     */
190
    function base_path($path = '')
191
    {
192
        return app()->basePath($path);
193
    }
194
}
195
 
196
if (! function_exists('bcrypt')) {
197
    /**
198
     * Hash the given value against the bcrypt algorithm.
199
     *
200
     * @param  string  $value
201
     * @param  array  $options
202
     * @return string
203
     */
204
    function bcrypt($value, $options = [])
205
    {
206
        return app('hash')->driver('bcrypt')->make($value, $options);
207
    }
208
}
209
 
210
if (! function_exists('broadcast')) {
211
    /**
212
     * Begin broadcasting an event.
213
     *
214
     * @param  mixed|null  $event
215
     * @return \Illuminate\Broadcasting\PendingBroadcast
216
     */
217
    function broadcast($event = null)
218
    {
219
        return app(BroadcastFactory::class)->event($event);
220
    }
221
}
222
 
223
if (! function_exists('cache')) {
224
    /**
225
     * Get / set the specified cache value.
226
     *
227
     * If an array is passed, we'll assume you want to put to the cache.
228
     *
229
     * @param  dynamic  key|key,default|data,expiration|null
230
     * @return mixed|\Illuminate\Cache\CacheManager
231
     *
232
     * @throws \InvalidArgumentException
233
     */
234
    function cache()
235
    {
236
        $arguments = func_get_args();
237
 
238
        if (empty($arguments)) {
239
            return app('cache');
240
        }
241
 
242
        if (is_string($arguments[0])) {
243
            return app('cache')->get(...$arguments);
244
        }
245
 
246
        if (! is_array($arguments[0])) {
247
            throw new InvalidArgumentException(
248
                'When setting a value in the cache, you must pass an array of key / value pairs.'
249
            );
250
        }
251
 
252
        return app('cache')->put(key($arguments[0]), reset($arguments[0]), $arguments[1] ?? null);
253
    }
254
}
255
 
256
if (! function_exists('config')) {
257
    /**
258
     * Get / set the specified configuration value.
259
     *
260
     * If an array is passed as the key, we will assume you want to set an array of values.
261
     *
262
     * @param  array|string|null  $key
263
     * @param  mixed  $default
264
     * @return mixed|\Illuminate\Config\Repository
265
     */
266
    function config($key = null, $default = null)
267
    {
268
        if (is_null($key)) {
269
            return app('config');
270
        }
271
 
272
        if (is_array($key)) {
273
            return app('config')->set($key);
274
        }
275
 
276
        return app('config')->get($key, $default);
277
    }
278
}
279
 
280
if (! function_exists('config_path')) {
281
    /**
282
     * Get the configuration path.
283
     *
284
     * @param  string  $path
285
     * @return string
286
     */
287
    function config_path($path = '')
288
    {
289
        return app()->configPath($path);
290
    }
291
}
292
 
293
if (! function_exists('cookie')) {
294
    /**
295
     * Create a new cookie instance.
296
     *
297
     * @param  string|null  $name
298
     * @param  string|null  $value
299
     * @param  int  $minutes
300
     * @param  string|null  $path
301
     * @param  string|null  $domain
302
     * @param  bool|null  $secure
303
     * @param  bool  $httpOnly
304
     * @param  bool  $raw
305
     * @param  string|null  $sameSite
306
     * @return \Illuminate\Cookie\CookieJar|\Symfony\Component\HttpFoundation\Cookie
307
     */
308
    function cookie($name = null, $value = null, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = true, $raw = false, $sameSite = null)
309
    {
310
        $cookie = app(CookieFactory::class);
311
 
312
        if (is_null($name)) {
313
            return $cookie;
314
        }
315
 
316
        return $cookie->make($name, $value, $minutes, $path, $domain, $secure, $httpOnly, $raw, $sameSite);
317
    }
318
}
319
 
320
if (! function_exists('csrf_field')) {
321
    /**
322
     * Generate a CSRF token form field.
323
     *
324
     * @return \Illuminate\Support\HtmlString
325
     */
326
    function csrf_field()
327
    {
328
        return new HtmlString('<input type="hidden" name="_token" value="'.csrf_token().'">');
329
    }
330
}
331
 
332
if (! function_exists('csrf_token')) {
333
    /**
334
     * Get the CSRF token value.
335
     *
336
     * @return string
337
     *
338
     * @throws \RuntimeException
339
     */
340
    function csrf_token()
341
    {
342
        $session = app('session');
343
 
344
        if (isset($session)) {
345
            return $session->token();
346
        }
347
 
348
        throw new RuntimeException('Application session store not set.');
349
    }
350
}
351
 
352
if (! function_exists('database_path')) {
353
    /**
354
     * Get the database path.
355
     *
356
     * @param  string  $path
357
     * @return string
358
     */
359
    function database_path($path = '')
360
    {
361
        return app()->databasePath($path);
362
    }
363
}
364
 
365
if (! function_exists('decrypt')) {
366
    /**
367
     * Decrypt the given value.
368
     *
369
     * @param  string  $value
370
     * @param  bool  $unserialize
371
     * @return mixed
372
     */
373
    function decrypt($value, $unserialize = true)
374
    {
375
        return app('encrypter')->decrypt($value, $unserialize);
376
    }
377
}
378
 
379
if (! function_exists('dispatch')) {
380
    /**
381
     * Dispatch a job to its appropriate handler.
382
     *
383
     * @param  mixed  $job
384
     * @return \Illuminate\Foundation\Bus\PendingDispatch
385
     */
386
    function dispatch($job)
387
    {
388
        return $job instanceof Closure
389
                ? new PendingClosureDispatch(CallQueuedClosure::create($job))
390
                : new PendingDispatch($job);
391
    }
392
}
393
 
394
if (! function_exists('dispatch_sync')) {
395
    /**
396
     * Dispatch a command to its appropriate handler in the current process.
397
     *
398
     * Queueable jobs will be dispatched to the "sync" queue.
399
     *
400
     * @param  mixed  $job
401
     * @param  mixed  $handler
402
     * @return mixed
403
     */
404
    function dispatch_sync($job, $handler = null)
405
    {
406
        return app(Dispatcher::class)->dispatchSync($job, $handler);
407
    }
408
}
409
 
410
if (! function_exists('dispatch_now')) {
411
    /**
412
     * Dispatch a command to its appropriate handler in the current process.
413
     *
414
     * @param  mixed  $job
415
     * @param  mixed  $handler
416
     * @return mixed
417
     *
418
     * @deprecated Will be removed in a future Laravel version.
419
     */
420
    function dispatch_now($job, $handler = null)
421
    {
422
        return app(Dispatcher::class)->dispatchNow($job, $handler);
423
    }
424
}
425
 
426
if (! function_exists('encrypt')) {
427
    /**
428
     * Encrypt the given value.
429
     *
430
     * @param  mixed  $value
431
     * @param  bool  $serialize
432
     * @return string
433
     */
434
    function encrypt($value, $serialize = true)
435
    {
436
        return app('encrypter')->encrypt($value, $serialize);
437
    }
438
}
439
 
440
if (! function_exists('event')) {
441
    /**
442
     * Dispatch an event and call the listeners.
443
     *
444
     * @param  string|object  $event
445
     * @param  mixed  $payload
446
     * @param  bool  $halt
447
     * @return array|null
448
     */
449
    function event(...$args)
450
    {
451
        return app('events')->dispatch(...$args);
452
    }
453
}
454
 
455
if (! function_exists('fake') && class_exists(\Faker\Factory::class)) {
456
    /**
457
     * Get a faker instance.
458
     *
150 lars 459
     * @param  string|null  $locale
148 lars 460
     * @return \Faker\Generator
461
     */
462
    function fake($locale = null)
463
    {
150 lars 464
        if (app()->bound('config')) {
465
            $locale ??= app('config')->get('app.faker_locale');
466
        }
148 lars 467
 
150 lars 468
        $locale ??= 'en_US';
469
 
148 lars 470
        $abstract = \Faker\Generator::class.':'.$locale;
471
 
472
        if (! app()->bound($abstract)) {
473
            app()->singleton($abstract, fn () => \Faker\Factory::create($locale));
474
        }
475
 
476
        return app()->make($abstract);
477
    }
478
}
479
 
480
if (! function_exists('info')) {
481
    /**
482
     * Write some information to the log.
483
     *
484
     * @param  string  $message
485
     * @param  array  $context
486
     * @return void
487
     */
488
    function info($message, $context = [])
489
    {
490
        app('log')->info($message, $context);
491
    }
492
}
493
 
494
if (! function_exists('logger')) {
495
    /**
496
     * Log a debug message to the logs.
497
     *
498
     * @param  string|null  $message
499
     * @param  array  $context
500
     * @return \Illuminate\Log\LogManager|null
501
     */
502
    function logger($message = null, array $context = [])
503
    {
504
        if (is_null($message)) {
505
            return app('log');
506
        }
507
 
508
        return app('log')->debug($message, $context);
509
    }
510
}
511
 
512
if (! function_exists('lang_path')) {
513
    /**
514
     * Get the path to the language folder.
515
     *
516
     * @param  string  $path
517
     * @return string
518
     */
519
    function lang_path($path = '')
520
    {
521
        return app()->langPath($path);
522
    }
523
}
524
 
525
if (! function_exists('logs')) {
526
    /**
527
     * Get a log driver instance.
528
     *
529
     * @param  string|null  $driver
530
     * @return \Illuminate\Log\LogManager|\Psr\Log\LoggerInterface
531
     */
532
    function logs($driver = null)
533
    {
534
        return $driver ? app('log')->driver($driver) : app('log');
535
    }
536
}
537
 
538
if (! function_exists('method_field')) {
539
    /**
540
     * Generate a form field to spoof the HTTP verb used by forms.
541
     *
542
     * @param  string  $method
543
     * @return \Illuminate\Support\HtmlString
544
     */
545
    function method_field($method)
546
    {
547
        return new HtmlString('<input type="hidden" name="_method" value="'.$method.'">');
548
    }
549
}
550
 
551
if (! function_exists('mix')) {
552
    /**
553
     * Get the path to a versioned Mix file.
554
     *
555
     * @param  string  $path
556
     * @param  string  $manifestDirectory
557
     * @return \Illuminate\Support\HtmlString|string
558
     *
559
     * @throws \Exception
560
     */
561
    function mix($path, $manifestDirectory = '')
562
    {
563
        return app(Mix::class)(...func_get_args());
564
    }
565
}
566
 
567
if (! function_exists('now')) {
568
    /**
569
     * Create a new Carbon instance for the current time.
570
     *
571
     * @param  \DateTimeZone|string|null  $tz
572
     * @return \Illuminate\Support\Carbon
573
     */
574
    function now($tz = null)
575
    {
576
        return Date::now($tz);
577
    }
578
}
579
 
580
if (! function_exists('old')) {
581
    /**
582
     * Retrieve an old input item.
583
     *
584
     * @param  string|null  $key
585
     * @param  mixed  $default
586
     * @return mixed
587
     */
588
    function old($key = null, $default = null)
589
    {
590
        return app('request')->old($key, $default);
591
    }
592
}
593
 
594
if (! function_exists('policy')) {
595
    /**
596
     * Get a policy instance for a given class.
597
     *
598
     * @param  object|string  $class
599
     * @return mixed
600
     *
601
     * @throws \InvalidArgumentException
602
     */
603
    function policy($class)
604
    {
605
        return app(Gate::class)->getPolicyFor($class);
606
    }
607
}
608
 
609
if (! function_exists('precognitive')) {
610
    /**
611
     * Handle a Precognition controller hook.
612
     *
613
     * @param  null|callable  $callable
614
     * @return mixed
615
     */
616
    function precognitive($callable = null)
617
    {
618
        $callable ??= function () {
619
            //
620
        };
621
 
622
        $payload = $callable(function ($default, $precognition = null) {
623
            $response = request()->isPrecognitive()
624
                ? ($precognition ?? $default)
625
                : $default;
626
 
627
            abort(Router::toResponse(request(), value($response)));
628
        });
629
 
630
        if (request()->isPrecognitive()) {
631
            abort(204);
632
        }
633
 
634
        return $payload;
635
    }
636
}
637
 
638
if (! function_exists('public_path')) {
639
    /**
640
     * Get the path to the public folder.
641
     *
642
     * @param  string  $path
643
     * @return string
644
     */
645
    function public_path($path = '')
646
    {
647
        return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
648
    }
649
}
650
 
651
if (! function_exists('redirect')) {
652
    /**
653
     * Get an instance of the redirector.
654
     *
655
     * @param  string|null  $to
656
     * @param  int  $status
657
     * @param  array  $headers
658
     * @param  bool|null  $secure
659
     * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
660
     */
661
    function redirect($to = null, $status = 302, $headers = [], $secure = null)
662
    {
663
        if (is_null($to)) {
664
            return app('redirect');
665
        }
666
 
667
        return app('redirect')->to($to, $status, $headers, $secure);
668
    }
669
}
670
 
671
if (! function_exists('report')) {
672
    /**
673
     * Report an exception.
674
     *
675
     * @param  \Throwable|string  $exception
676
     * @return void
677
     */
678
    function report($exception)
679
    {
680
        if (is_string($exception)) {
681
            $exception = new Exception($exception);
682
        }
683
 
684
        app(ExceptionHandler::class)->report($exception);
685
    }
686
}
687
 
688
if (! function_exists('report_if')) {
689
    /**
690
     * Report an exception if the given condition is true.
691
     *
692
     * @param  bool  $boolean
693
     * @param  \Throwable|string  $exception
694
     * @return void
695
     */
696
    function report_if($boolean, $exception)
697
    {
698
        if ($boolean) {
699
            report($exception);
700
        }
701
    }
702
}
703
 
704
if (! function_exists('report_unless')) {
705
    /**
706
     * Report an exception unless the given condition is true.
707
     *
708
     * @param  bool  $boolean
709
     * @param  \Throwable|string  $exception
710
     * @return void
711
     */
712
    function report_unless($boolean, $exception)
713
    {
714
        if (! $boolean) {
715
            report($exception);
716
        }
717
    }
718
}
719
 
720
if (! function_exists('request')) {
721
    /**
722
     * Get an instance of the current request or an input item from the request.
723
     *
724
     * @param  array|string|null  $key
725
     * @param  mixed  $default
726
     * @return mixed|\Illuminate\Http\Request|string|array|null
727
     */
728
    function request($key = null, $default = null)
729
    {
730
        if (is_null($key)) {
731
            return app('request');
732
        }
733
 
734
        if (is_array($key)) {
735
            return app('request')->only($key);
736
        }
737
 
738
        $value = app('request')->__get($key);
739
 
740
        return is_null($value) ? value($default) : $value;
741
    }
742
}
743
 
744
if (! function_exists('rescue')) {
745
    /**
746
     * Catch a potential exception and return a default value.
747
     *
748
     * @param  callable  $callback
749
     * @param  mixed  $rescue
750
     * @param  bool|callable  $report
751
     * @return mixed
752
     */
753
    function rescue(callable $callback, $rescue = null, $report = true)
754
    {
755
        try {
756
            return $callback();
757
        } catch (Throwable $e) {
758
            if (value($report, $e)) {
759
                report($e);
760
            }
761
 
762
            return value($rescue, $e);
763
        }
764
    }
765
}
766
 
767
if (! function_exists('resolve')) {
768
    /**
769
     * Resolve a service from the container.
770
     *
771
     * @param  string  $name
772
     * @param  array  $parameters
773
     * @return mixed
774
     */
775
    function resolve($name, array $parameters = [])
776
    {
777
        return app($name, $parameters);
778
    }
779
}
780
 
781
if (! function_exists('resource_path')) {
782
    /**
783
     * Get the path to the resources folder.
784
     *
785
     * @param  string  $path
786
     * @return string
787
     */
788
    function resource_path($path = '')
789
    {
790
        return app()->resourcePath($path);
791
    }
792
}
793
 
794
if (! function_exists('response')) {
795
    /**
796
     * Return a new response from the application.
797
     *
798
     * @param  \Illuminate\Contracts\View\View|string|array|null  $content
799
     * @param  int  $status
800
     * @param  array  $headers
801
     * @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
802
     */
803
    function response($content = '', $status = 200, array $headers = [])
804
    {
805
        $factory = app(ResponseFactory::class);
806
 
807
        if (func_num_args() === 0) {
808
            return $factory;
809
        }
810
 
811
        return $factory->make($content, $status, $headers);
812
    }
813
}
814
 
815
if (! function_exists('route')) {
816
    /**
817
     * Generate the URL to a named route.
818
     *
819
     * @param  array|string  $name
820
     * @param  mixed  $parameters
821
     * @param  bool  $absolute
822
     * @return string
823
     */
824
    function route($name, $parameters = [], $absolute = true)
825
    {
826
        return app('url')->route($name, $parameters, $absolute);
827
    }
828
}
829
 
830
if (! function_exists('secure_asset')) {
831
    /**
832
     * Generate an asset path for the application.
833
     *
834
     * @param  string  $path
835
     * @return string
836
     */
837
    function secure_asset($path)
838
    {
839
        return asset($path, true);
840
    }
841
}
842
 
843
if (! function_exists('secure_url')) {
844
    /**
845
     * Generate a HTTPS url for the application.
846
     *
847
     * @param  string  $path
848
     * @param  mixed  $parameters
849
     * @return string
850
     */
851
    function secure_url($path, $parameters = [])
852
    {
853
        return url($path, $parameters, true);
854
    }
855
}
856
 
857
if (! function_exists('session')) {
858
    /**
859
     * Get / set the specified session value.
860
     *
861
     * If an array is passed as the key, we will assume you want to set an array of values.
862
     *
863
     * @param  array|string|null  $key
864
     * @param  mixed  $default
865
     * @return mixed|\Illuminate\Session\Store|\Illuminate\Session\SessionManager
866
     */
867
    function session($key = null, $default = null)
868
    {
869
        if (is_null($key)) {
870
            return app('session');
871
        }
872
 
873
        if (is_array($key)) {
874
            return app('session')->put($key);
875
        }
876
 
877
        return app('session')->get($key, $default);
878
    }
879
}
880
 
881
if (! function_exists('storage_path')) {
882
    /**
883
     * Get the path to the storage folder.
884
     *
885
     * @param  string  $path
886
     * @return string
887
     */
888
    function storage_path($path = '')
889
    {
890
        return app()->storagePath($path);
891
    }
892
}
893
 
894
if (! function_exists('to_route')) {
895
    /**
896
     * Create a new redirect response to a named route.
897
     *
898
     * @param  string  $route
899
     * @param  mixed  $parameters
900
     * @param  int  $status
901
     * @param  array  $headers
902
     * @return \Illuminate\Http\RedirectResponse
903
     */
904
    function to_route($route, $parameters = [], $status = 302, $headers = [])
905
    {
906
        return redirect()->route($route, $parameters, $status, $headers);
907
    }
908
}
909
 
910
if (! function_exists('today')) {
911
    /**
912
     * Create a new Carbon instance for the current date.
913
     *
914
     * @param  \DateTimeZone|string|null  $tz
915
     * @return \Illuminate\Support\Carbon
916
     */
917
    function today($tz = null)
918
    {
919
        return Date::today($tz);
920
    }
921
}
922
 
923
if (! function_exists('trans')) {
924
    /**
925
     * Translate the given message.
926
     *
927
     * @param  string|null  $key
928
     * @param  array  $replace
929
     * @param  string|null  $locale
930
     * @return \Illuminate\Contracts\Translation\Translator|string|array|null
931
     */
932
    function trans($key = null, $replace = [], $locale = null)
933
    {
934
        if (is_null($key)) {
935
            return app('translator');
936
        }
937
 
938
        return app('translator')->get($key, $replace, $locale);
939
    }
940
}
941
 
942
if (! function_exists('trans_choice')) {
943
    /**
944
     * Translates the given message based on a count.
945
     *
946
     * @param  string  $key
947
     * @param  \Countable|int|array  $number
948
     * @param  array  $replace
949
     * @param  string|null  $locale
950
     * @return string
951
     */
952
    function trans_choice($key, $number, array $replace = [], $locale = null)
953
    {
954
        return app('translator')->choice($key, $number, $replace, $locale);
955
    }
956
}
957
 
958
if (! function_exists('__')) {
959
    /**
960
     * Translate the given message.
961
     *
962
     * @param  string|null  $key
963
     * @param  array  $replace
964
     * @param  string|null  $locale
965
     * @return string|array|null
966
     */
967
    function __($key = null, $replace = [], $locale = null)
968
    {
969
        if (is_null($key)) {
970
            return $key;
971
        }
972
 
973
        return trans($key, $replace, $locale);
974
    }
975
}
976
 
977
if (! function_exists('url')) {
978
    /**
979
     * Generate a url for the application.
980
     *
981
     * @param  string|null  $path
982
     * @param  mixed  $parameters
983
     * @param  bool|null  $secure
984
     * @return \Illuminate\Contracts\Routing\UrlGenerator|string
985
     */
986
    function url($path = null, $parameters = [], $secure = null)
987
    {
988
        if (is_null($path)) {
989
            return app(UrlGenerator::class);
990
        }
991
 
992
        return app(UrlGenerator::class)->to($path, $parameters, $secure);
993
    }
994
}
995
 
996
if (! function_exists('validator')) {
997
    /**
998
     * Create a new Validator instance.
999
     *
1000
     * @param  array  $data
1001
     * @param  array  $rules
1002
     * @param  array  $messages
1003
     * @param  array  $customAttributes
1004
     * @return \Illuminate\Contracts\Validation\Validator|\Illuminate\Contracts\Validation\Factory
1005
     */
1006
    function validator(array $data = [], array $rules = [], array $messages = [], array $customAttributes = [])
1007
    {
1008
        $factory = app(ValidationFactory::class);
1009
 
1010
        if (func_num_args() === 0) {
1011
            return $factory;
1012
        }
1013
 
1014
        return $factory->make($data, $rules, $messages, $customAttributes);
1015
    }
1016
}
1017
 
1018
if (! function_exists('view')) {
1019
    /**
1020
     * Get the evaluated view contents for the given view.
1021
     *
1022
     * @param  string|null  $view
1023
     * @param  \Illuminate\Contracts\Support\Arrayable|array  $data
1024
     * @param  array  $mergeData
1025
     * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
1026
     */
1027
    function view($view = null, $data = [], $mergeData = [])
1028
    {
1029
        $factory = app(ViewFactory::class);
1030
 
1031
        if (func_num_args() === 0) {
1032
            return $factory;
1033
        }
1034
 
1035
        return $factory->make($view, $data, $mergeData);
1036
    }
1037
}