Debian Codegraph @

lib/3rdParty/composer/illuminate/support/functions.php

raw symbols SCIP
1 <?php
2
3 namespace Illuminate\Support;
4
5 use Carbon\CarbonInterface;
6 use Carbon\CarbonInterval;
7 use Illuminate\Support\Defer\DeferredCallback;
8 use Illuminate\Support\Defer\DeferredCallbackCollection;
9 use Illuminate\Support\Facades\Date;
10 use Symfony\Component\Process\PhpExecutableFinder;
11
12 if (! function_exists('Illuminate\Support\defer')) {
13 /**
14 * Defer execution of the given callback.
15 *
16 * @param callable|null $callback
17 * @param string|null $name
18 * @param bool $always
19 * @return ($callback is null ? \Illuminate\Support\Defer\DeferredCallbackCollection : \Illuminate\Support\Defer\DeferredCallback)
20 */
21 function defer(?callable $callback = null, ?string $name = null, bool $always = false): DeferredCallback|DeferredCallbackCollection
22 {
23 if ($callback === null) {
24 return app(DeferredCallbackCollection::class);
25 }
26
27 return tap(
28 new DeferredCallback($callback, $name, $always),
29 fn ($deferred) => app(DeferredCallbackCollection::class)[] = $deferred
30 );
31 }
32 }
33
34 if (! function_exists('Illuminate\Support\php_binary')) {
35 /**
36 * Determine the PHP Binary.
37 */
38 function php_binary(): string
39 {
40 return (new PhpExecutableFinder)->find(false) ?: 'php';
41 }
42 }
43
44 if (! function_exists('Illuminate\Support\artisan_binary')) {
45 /**
46 * Determine the proper Artisan executable.
47 */
48 function artisan_binary(): string
49 {
50 return defined('ARTISAN_BINARY') ? ARTISAN_BINARY : 'artisan';
51 }
52 }
53
54 // Time functions...
55
56 if (! function_exists('Illuminate\Support\now')) {
57 /**
58 * Create a new Carbon instance for the current time.
59 *
60 * @param \DateTimeZone|\UnitEnum|string|null $tz
61 * @return \Illuminate\Support\Carbon
62 */
63 function now($tz = null): CarbonInterface
64 {
65 return Date::now(enum_value($tz));
66 }
67 }
68
69 if (! function_exists('Illuminate\Support\microseconds')) {
70 /**
71 * Get the current date / time plus the given number of microseconds.
72 */
73 function microseconds(int|float $microseconds): CarbonInterval
74 {
75 return CarbonInterval::microseconds($microseconds);
76 }
77 }
78
79 if (! function_exists('Illuminate\Support\milliseconds')) {
80 /**
81 * Get the current date / time plus the given number of milliseconds.
82 */
83 function milliseconds(int|float $milliseconds): CarbonInterval
84 {
85 return CarbonInterval::milliseconds($milliseconds);
86 }
87 }
88
89 if (! function_exists('Illuminate\Support\seconds')) {
90 /**
91 * Get the current date / time plus the given number of seconds.
92 */
93 function seconds(int|float $seconds): CarbonInterval
94 {
95 return CarbonInterval::seconds($seconds);
96 }
97 }
98
99 if (! function_exists('Illuminate\Support\minutes')) {
100 /**
101 * Get the current date / time plus the given number of minutes.
102 */
103 function minutes(int|float $minutes): CarbonInterval
104 {
105 return CarbonInterval::minutes($minutes);
106 }
107 }
108
109 if (! function_exists('Illuminate\Support\hours')) {
110 /**
111 * Get the current date / time plus the given number of hours.
112 */
113 function hours(int|float $hours): CarbonInterval
114 {
115 return CarbonInterval::hours($hours);
116 }
117 }
118
119 if (! function_exists('Illuminate\Support\days')) {
120 /**
121 * Get the current date / time plus the given number of days.
122 */
123 function days(int|float $days): CarbonInterval
124 {
125 return CarbonInterval::days($days);
126 }
127 }
128
129 if (! function_exists('Illuminate\Support\weeks')) {
130 /**
131 * Get the current date / time plus the given number of weeks.
132 */
133 function weeks(int $weeks): CarbonInterval
134 {
135 return CarbonInterval::weeks($weeks);
136 }
137 }
138
139 if (! function_exists('Illuminate\Support\months')) {
140 /**
141 * Get the current date / time plus the given number of months.
142 */
143 function months(int $months): CarbonInterval
144 {
145 return CarbonInterval::months($months);
146 }
147 }
148
149 if (! function_exists('Illuminate\Support\years')) {
150 /**
151 * Get the current date / time plus the given number of years.
152 */
153 function years(int $years): CarbonInterval
154 {
155 return CarbonInterval::years($years);
156 }
157 }