1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,230 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-namespace Illuminate\Support; |
|
4 |
- |
|
5 |
-use Carbon\Factory; |
|
6 |
-use InvalidArgumentException; |
|
7 |
- |
|
8 |
-/** |
|
9 |
- * @see https://carbon.nesbot.com/docs/ |
|
10 |
- * @see https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Factory.php |
|
11 |
- * |
|
12 |
- * @method static Carbon create($year = 0, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0, $tz = null) |
|
13 |
- * @method static Carbon createFromDate($year = null, $month = null, $day = null, $tz = null) |
|
14 |
- * @method static Carbon|false createFromFormat($format, $time, $tz = null) |
|
15 |
- * @method static Carbon createFromTime($hour = 0, $minute = 0, $second = 0, $tz = null) |
|
16 |
- * @method static Carbon createFromTimeString($time, $tz = null) |
|
17 |
- * @method static Carbon createFromTimestamp($timestamp, $tz = null) |
|
18 |
- * @method static Carbon createFromTimestampMs($timestamp, $tz = null) |
|
19 |
- * @method static Carbon createFromTimestampUTC($timestamp) |
|
20 |
- * @method static Carbon createMidnightDate($year = null, $month = null, $day = null, $tz = null) |
|
21 |
- * @method static Carbon|false createSafe($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null) |
|
22 |
- * @method static Carbon disableHumanDiffOption($humanDiffOption) |
|
23 |
- * @method static Carbon enableHumanDiffOption($humanDiffOption) |
|
24 |
- * @method static mixed executeWithLocale($locale, $func) |
|
25 |
- * @method static Carbon fromSerialized($value) |
|
26 |
- * @method static array getAvailableLocales() |
|
27 |
- * @method static array getDays() |
|
28 |
- * @method static int getHumanDiffOptions() |
|
29 |
- * @method static array getIsoUnits() |
|
30 |
- * @method static Carbon getLastErrors() |
|
31 |
- * @method static string getLocale() |
|
32 |
- * @method static int getMidDayAt() |
|
33 |
- * @method static Carbon getTestNow() |
|
34 |
- * @method static \Symfony\Component\Translation\TranslatorInterface getTranslator() |
|
35 |
- * @method static int getWeekEndsAt() |
|
36 |
- * @method static int getWeekStartsAt() |
|
37 |
- * @method static array getWeekendDays() |
|
38 |
- * @method static bool hasFormat($date, $format) |
|
39 |
- * @method static bool hasMacro($name) |
|
40 |
- * @method static bool hasRelativeKeywords($time) |
|
41 |
- * @method static bool hasTestNow() |
|
42 |
- * @method static Carbon instance($date) |
|
43 |
- * @method static bool isImmutable() |
|
44 |
- * @method static bool isModifiableUnit($unit) |
|
45 |
- * @method static Carbon isMutable() |
|
46 |
- * @method static bool isStrictModeEnabled() |
|
47 |
- * @method static bool localeHasDiffOneDayWords($locale) |
|
48 |
- * @method static bool localeHasDiffSyntax($locale) |
|
49 |
- * @method static bool localeHasDiffTwoDayWords($locale) |
|
50 |
- * @method static bool localeHasPeriodSyntax($locale) |
|
51 |
- * @method static bool localeHasShortUnits($locale) |
|
52 |
- * @method static void macro($name, $macro) |
|
53 |
- * @method static Carbon|null make($var) |
|
54 |
- * @method static Carbon maxValue() |
|
55 |
- * @method static Carbon minValue() |
|
56 |
- * @method static void mixin($mixin) |
|
57 |
- * @method static Carbon now($tz = null) |
|
58 |
- * @method static Carbon parse($time = null, $tz = null) |
|
59 |
- * @method static string pluralUnit(string $unit) |
|
60 |
- * @method static void resetMonthsOverflow() |
|
61 |
- * @method static void resetToStringFormat() |
|
62 |
- * @method static void resetYearsOverflow() |
|
63 |
- * @method static void serializeUsing($callback) |
|
64 |
- * @method static Carbon setHumanDiffOptions($humanDiffOptions) |
|
65 |
- * @method static bool setLocale($locale) |
|
66 |
- * @method static void setMidDayAt($hour) |
|
67 |
- * @method static Carbon setTestNow($testNow = null) |
|
68 |
- * @method static void setToStringFormat($format) |
|
69 |
- * @method static void setTranslator(\Symfony\Component\Translation\TranslatorInterface $translator) |
|
70 |
- * @method static Carbon setUtf8($utf8) |
|
71 |
- * @method static void setWeekEndsAt($day) |
|
72 |
- * @method static void setWeekStartsAt($day) |
|
73 |
- * @method static void setWeekendDays($days) |
|
74 |
- * @method static bool shouldOverflowMonths() |
|
75 |
- * @method static bool shouldOverflowYears() |
|
76 |
- * @method static string singularUnit(string $unit) |
|
77 |
- * @method static Carbon today($tz = null) |
|
78 |
- * @method static Carbon tomorrow($tz = null) |
|
79 |
- * @method static void useMonthsOverflow($monthsOverflow = true) |
|
80 |
- * @method static Carbon useStrictMode($strictModeEnabled = true) |
|
81 |
- * @method static void useYearsOverflow($yearsOverflow = true) |
|
82 |
- * @method static Carbon yesterday($tz = null) |
|
83 |
- */ |
|
84 |
-class DateFactory |
|
85 |
-{ |
|
86 |
- /** |
|
87 |
- * The default class that will be used for all created dates. |
|
88 |
- * |
|
89 |
- * @var string |
|
90 |
- */ |
|
91 |
- const DEFAULT_CLASS_NAME = Carbon::class; |
|
92 |
- |
|
93 |
- /** |
|
94 |
- * The type (class) of dates that should be created. |
|
95 |
- * |
|
96 |
- * @var string |
|
97 |
- */ |
|
98 |
- protected static $dateClass; |
|
99 |
- |
|
100 |
- /** |
|
101 |
- * This callable may be used to intercept date creation. |
|
102 |
- * |
|
103 |
- * @var callable |
|
104 |
- */ |
|
105 |
- protected static $callable; |
|
106 |
- |
|
107 |
- /** |
|
108 |
- * The Carbon factory that should be used when creating dates. |
|
109 |
- * |
|
110 |
- * @var object |
|
111 |
- */ |
|
112 |
- protected static $factory; |
|
113 |
- |
|
114 |
- /** |
|
115 |
- * Use the given handler when generating dates (class name, callable, or factory). |
|
116 |
- * |
|
117 |
- * @param mixed $handler |
|
118 |
- * |
|
119 |
- * @throws \InvalidArgumentException |
|
120 |
- */ |
|
121 |
- public static function use($handler) |
|
122 |
- { |
|
123 |
- if (is_callable($handler) && is_object($handler)) { |
|
124 |
- return static::useCallable($handler); |
|
125 |
- } elseif (is_string($handler)) { |
|
126 |
- return static::useClass($handler); |
|
127 |
- } elseif ($handler instanceof Factory) { |
|
128 |
- return static::useFactory($handler); |
|
129 |
- } |
|
130 |
- |
|
131 |
- throw new InvalidArgumentException('Invalid date creation handler. Please provide a class name, callable, or Carbon factory.'); |
|
132 |
- } |
|
133 |
- |
|
134 |
- /** |
|
135 |
- * Use the default date class when generating dates. |
|
136 |
- * |
|
137 |
- * @return void |
|
138 |
- */ |
|
139 |
- public static function useDefault() |
|
140 |
- { |
|
141 |
- static::$dateClass = null; |
|
142 |
- static::$callable = null; |
|
143 |
- static::$factory = null; |
|
144 |
- } |
|
145 |
- |
|
146 |
- /** |
|
147 |
- * Execute the given callable on each date creation. |
|
148 |
- * |
|
149 |
- * @param callable $callable |
|
150 |
- * @return void |
|
151 |
- */ |
|
152 |
- public static function useCallable(callable $callable) |
|
153 |
- { |
|
154 |
- static::$callable = $callable; |
|
155 |
- |
|
156 |
- static::$dateClass = null; |
|
157 |
- static::$factory = null; |
|
158 |
- } |
|
159 |
- |
|
160 |
- /** |
|
161 |
- * Use the given date type (class) when generating dates. |
|
162 |
- * |
|
163 |
- * @param string $dateClass |
|
164 |
- * @return void |
|
165 |
- */ |
|
166 |
- public static function useClass($dateClass) |
|
167 |
- { |
|
168 |
- static::$dateClass = $dateClass; |
|
169 |
- |
|
170 |
- static::$factory = null; |
|
171 |
- static::$callable = null; |
|
172 |
- } |
|
173 |
- |
|
174 |
- /** |
|
175 |
- * Use the given Carbon factory when generating dates. |
|
176 |
- * |
|
177 |
- * @param object $factory |
|
178 |
- * @return void |
|
179 |
- */ |
|
180 |
- public static function useFactory($factory) |
|
181 |
- { |
|
182 |
- static::$factory = $factory; |
|
183 |
- |
|
184 |
- static::$dateClass = null; |
|
185 |
- static::$callable = null; |
|
186 |
- } |
|
187 |
- |
|
188 |
- /** |
|
189 |
- * Handle dynamic calls to generate dates. |
|
190 |
- * |
|
191 |
- * @param string $method |
|
192 |
- * @param array $parameters |
|
193 |
- * @return mixed |
|
194 |
- * |
|
195 |
- * @throws \RuntimeException |
|
196 |
- */ |
|
197 |
- public function __call($method, $parameters) |
|
198 |
- { |
|
199 |
- $defaultClassName = static::DEFAULT_CLASS_NAME; |
|
200 |
- |
|
201 |
- // Using callable to generate dates... |
|
202 |
- if (static::$callable) { |
|
203 |
- return call_user_func(static::$callable, $defaultClassName::$method(...$parameters)); |
|
204 |
- } |
|
205 |
- |
|
206 |
- // Using Carbon factory to generate dates... |
|
207 |
- if (static::$factory) { |
|
208 |
- return static::$factory->$method(...$parameters); |
|
209 |
- } |
|
210 |
- |
|
211 |
- $dateClass = static::$dateClass ?: $defaultClassName; |
|
212 |
- |
|
213 |
- // Check if date can be created using public class method... |
|
214 |
- if (method_exists($dateClass, $method) || |
|
215 |
- method_exists($dateClass, 'hasMacro') && $dateClass::hasMacro($method)) { |
|
216 |
- return $dateClass::$method(...$parameters); |
|
217 |
- } |
|
218 |
- |
|
219 |
- // If that fails, create the date with the default class.. |
|
220 |
- $date = $defaultClassName::$method(...$parameters); |
|
221 |
- |
|
222 |
- // If the configured class has an "instance" method, we'll try to pass our date into there... |
|
223 |
- if (method_exists($dateClass, 'instance')) { |
|
224 |
- return $dateClass::instance($date); |
|
225 |
- } |
|
226 |
- |
|
227 |
- // Otherwise, assume the configured class has a DateTime compatible constructor... |
|
228 |
- return new $dateClass($date->format('Y-m-d H:i:s.u'), $date->getTimezone()); |
|
229 |
- } |
|
230 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,230 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+namespace Illuminate\Support; |
|
4 |
+ |
|
5 |
+use Carbon\Factory; |
|
6 |
+use InvalidArgumentException; |
|
7 |
+ |
|
8 |
+/** |
|
9 |
+ * @see https://carbon.nesbot.com/docs/ |
|
10 |
+ * @see https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Factory.php |
|
11 |
+ * |
|
12 |
+ * @method static Carbon create($year = 0, $month = 1, $day = 1, $hour = 0, $minute = 0, $second = 0, $tz = null) |
|
13 |
+ * @method static Carbon createFromDate($year = null, $month = null, $day = null, $tz = null) |
|
14 |
+ * @method static Carbon|false createFromFormat($format, $time, $tz = null) |
|
15 |
+ * @method static Carbon createFromTime($hour = 0, $minute = 0, $second = 0, $tz = null) |
|
16 |
+ * @method static Carbon createFromTimeString($time, $tz = null) |
|
17 |
+ * @method static Carbon createFromTimestamp($timestamp, $tz = null) |
|
18 |
+ * @method static Carbon createFromTimestampMs($timestamp, $tz = null) |
|
19 |
+ * @method static Carbon createFromTimestampUTC($timestamp) |
|
20 |
+ * @method static Carbon createMidnightDate($year = null, $month = null, $day = null, $tz = null) |
|
21 |
+ * @method static Carbon|false createSafe($year = null, $month = null, $day = null, $hour = null, $minute = null, $second = null, $tz = null) |
|
22 |
+ * @method static Carbon disableHumanDiffOption($humanDiffOption) |
|
23 |
+ * @method static Carbon enableHumanDiffOption($humanDiffOption) |
|
24 |
+ * @method static mixed executeWithLocale($locale, $func) |
|
25 |
+ * @method static Carbon fromSerialized($value) |
|
26 |
+ * @method static array getAvailableLocales() |
|
27 |
+ * @method static array getDays() |
|
28 |
+ * @method static int getHumanDiffOptions() |
|
29 |
+ * @method static array getIsoUnits() |
|
30 |
+ * @method static Carbon getLastErrors() |
|
31 |
+ * @method static string getLocale() |
|
32 |
+ * @method static int getMidDayAt() |
|
33 |
+ * @method static Carbon getTestNow() |
|
34 |
+ * @method static \Symfony\Component\Translation\TranslatorInterface getTranslator() |
|
35 |
+ * @method static int getWeekEndsAt() |
|
36 |
+ * @method static int getWeekStartsAt() |
|
37 |
+ * @method static array getWeekendDays() |
|
38 |
+ * @method static bool hasFormat($date, $format) |
|
39 |
+ * @method static bool hasMacro($name) |
|
40 |
+ * @method static bool hasRelativeKeywords($time) |
|
41 |
+ * @method static bool hasTestNow() |
|
42 |
+ * @method static Carbon instance($date) |
|
43 |
+ * @method static bool isImmutable() |
|
44 |
+ * @method static bool isModifiableUnit($unit) |
|
45 |
+ * @method static Carbon isMutable() |
|
46 |
+ * @method static bool isStrictModeEnabled() |
|
47 |
+ * @method static bool localeHasDiffOneDayWords($locale) |
|
48 |
+ * @method static bool localeHasDiffSyntax($locale) |
|
49 |
+ * @method static bool localeHasDiffTwoDayWords($locale) |
|
50 |
+ * @method static bool localeHasPeriodSyntax($locale) |
|
51 |
+ * @method static bool localeHasShortUnits($locale) |
|
52 |
+ * @method static void macro($name, $macro) |
|
53 |
+ * @method static Carbon|null make($var) |
|
54 |
+ * @method static Carbon maxValue() |
|
55 |
+ * @method static Carbon minValue() |
|
56 |
+ * @method static void mixin($mixin) |
|
57 |
+ * @method static Carbon now($tz = null) |
|
58 |
+ * @method static Carbon parse($time = null, $tz = null) |
|
59 |
+ * @method static string pluralUnit(string $unit) |
|
60 |
+ * @method static void resetMonthsOverflow() |
|
61 |
+ * @method static void resetToStringFormat() |
|
62 |
+ * @method static void resetYearsOverflow() |
|
63 |
+ * @method static void serializeUsing($callback) |
|
64 |
+ * @method static Carbon setHumanDiffOptions($humanDiffOptions) |
|
65 |
+ * @method static bool setLocale($locale) |
|
66 |
+ * @method static void setMidDayAt($hour) |
|
67 |
+ * @method static Carbon setTestNow($testNow = null) |
|
68 |
+ * @method static void setToStringFormat($format) |
|
69 |
+ * @method static void setTranslator(\Symfony\Component\Translation\TranslatorInterface $translator) |
|
70 |
+ * @method static Carbon setUtf8($utf8) |
|
71 |
+ * @method static void setWeekEndsAt($day) |
|
72 |
+ * @method static void setWeekStartsAt($day) |
|
73 |
+ * @method static void setWeekendDays($days) |
|
74 |
+ * @method static bool shouldOverflowMonths() |
|
75 |
+ * @method static bool shouldOverflowYears() |
|
76 |
+ * @method static string singularUnit(string $unit) |
|
77 |
+ * @method static Carbon today($tz = null) |
|
78 |
+ * @method static Carbon tomorrow($tz = null) |
|
79 |
+ * @method static void useMonthsOverflow($monthsOverflow = true) |
|
80 |
+ * @method static Carbon useStrictMode($strictModeEnabled = true) |
|
81 |
+ * @method static void useYearsOverflow($yearsOverflow = true) |
|
82 |
+ * @method static Carbon yesterday($tz = null) |
|
83 |
+ */ |
|
84 |
+class DateFactory |
|
85 |
+{ |
|
86 |
+ /** |
|
87 |
+ * The default class that will be used for all created dates. |
|
88 |
+ * |
|
89 |
+ * @var string |
|
90 |
+ */ |
|
91 |
+ const DEFAULT_CLASS_NAME = Carbon::class; |
|
92 |
+ |
|
93 |
+ /** |
|
94 |
+ * The type (class) of dates that should be created. |
|
95 |
+ * |
|
96 |
+ * @var string |
|
97 |
+ */ |
|
98 |
+ protected static $dateClass; |
|
99 |
+ |
|
100 |
+ /** |
|
101 |
+ * This callable may be used to intercept date creation. |
|
102 |
+ * |
|
103 |
+ * @var callable |
|
104 |
+ */ |
|
105 |
+ protected static $callable; |
|
106 |
+ |
|
107 |
+ /** |
|
108 |
+ * The Carbon factory that should be used when creating dates. |
|
109 |
+ * |
|
110 |
+ * @var object |
|
111 |
+ */ |
|
112 |
+ protected static $factory; |
|
113 |
+ |
|
114 |
+ /** |
|
115 |
+ * Use the given handler when generating dates (class name, callable, or factory). |
|
116 |
+ * |
|
117 |
+ * @param mixed $handler |
|
118 |
+ * |
|
119 |
+ * @throws \InvalidArgumentException |
|
120 |
+ */ |
|
121 |
+ public static function use($handler) |
|
122 |
+ { |
|
123 |
+ if (is_callable($handler) && is_object($handler)) { |
|
124 |
+ return static::useCallable($handler); |
|
125 |
+ } elseif (is_string($handler)) { |
|
126 |
+ return static::useClass($handler); |
|
127 |
+ } elseif ($handler instanceof Factory) { |
|
128 |
+ return static::useFactory($handler); |
|
129 |
+ } |
|
130 |
+ |
|
131 |
+ throw new InvalidArgumentException('Invalid date creation handler. Please provide a class name, callable, or Carbon factory.'); |
|
132 |
+ } |
|
133 |
+ |
|
134 |
+ /** |
|
135 |
+ * Use the default date class when generating dates. |
|
136 |
+ * |
|
137 |
+ * @return void |
|
138 |
+ */ |
|
139 |
+ public static function useDefault() |
|
140 |
+ { |
|
141 |
+ static::$dateClass = null; |
|
142 |
+ static::$callable = null; |
|
143 |
+ static::$factory = null; |
|
144 |
+ } |
|
145 |
+ |
|
146 |
+ /** |
|
147 |
+ * Execute the given callable on each date creation. |
|
148 |
+ * |
|
149 |
+ * @param callable $callable |
|
150 |
+ * @return void |
|
151 |
+ */ |
|
152 |
+ public static function useCallable(callable $callable) |
|
153 |
+ { |
|
154 |
+ static::$callable = $callable; |
|
155 |
+ |
|
156 |
+ static::$dateClass = null; |
|
157 |
+ static::$factory = null; |
|
158 |
+ } |
|
159 |
+ |
|
160 |
+ /** |
|
161 |
+ * Use the given date type (class) when generating dates. |
|
162 |
+ * |
|
163 |
+ * @param string $dateClass |
|
164 |
+ * @return void |
|
165 |
+ */ |
|
166 |
+ public static function useClass($dateClass) |
|
167 |
+ { |
|
168 |
+ static::$dateClass = $dateClass; |
|
169 |
+ |
|
170 |
+ static::$factory = null; |
|
171 |
+ static::$callable = null; |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ /** |
|
175 |
+ * Use the given Carbon factory when generating dates. |
|
176 |
+ * |
|
177 |
+ * @param object $factory |
|
178 |
+ * @return void |
|
179 |
+ */ |
|
180 |
+ public static function useFactory($factory) |
|
181 |
+ { |
|
182 |
+ static::$factory = $factory; |
|
183 |
+ |
|
184 |
+ static::$dateClass = null; |
|
185 |
+ static::$callable = null; |
|
186 |
+ } |
|
187 |
+ |
|
188 |
+ /** |
|
189 |
+ * Handle dynamic calls to generate dates. |
|
190 |
+ * |
|
191 |
+ * @param string $method |
|
192 |
+ * @param array $parameters |
|
193 |
+ * @return mixed |
|
194 |
+ * |
|
195 |
+ * @throws \RuntimeException |
|
196 |
+ */ |
|
197 |
+ public function __call($method, $parameters) |
|
198 |
+ { |
|
199 |
+ $defaultClassName = static::DEFAULT_CLASS_NAME; |
|
200 |
+ |
|
201 |
+ // Using callable to generate dates... |
|
202 |
+ if (static::$callable) { |
|
203 |
+ return call_user_func(static::$callable, $defaultClassName::$method(...$parameters)); |
|
204 |
+ } |
|
205 |
+ |
|
206 |
+ // Using Carbon factory to generate dates... |
|
207 |
+ if (static::$factory) { |
|
208 |
+ return static::$factory->$method(...$parameters); |
|
209 |
+ } |
|
210 |
+ |
|
211 |
+ $dateClass = static::$dateClass ?: $defaultClassName; |
|
212 |
+ |
|
213 |
+ // Check if date can be created using public class method... |
|
214 |
+ if (method_exists($dateClass, $method) || |
|
215 |
+ method_exists($dateClass, 'hasMacro') && $dateClass::hasMacro($method)) { |
|
216 |
+ return $dateClass::$method(...$parameters); |
|
217 |
+ } |
|
218 |
+ |
|
219 |
+ // If that fails, create the date with the default class.. |
|
220 |
+ $date = $defaultClassName::$method(...$parameters); |
|
221 |
+ |
|
222 |
+ // If the configured class has an "instance" method, we'll try to pass our date into there... |
|
223 |
+ if (method_exists($dateClass, 'instance')) { |
|
224 |
+ return $dateClass::instance($date); |
|
225 |
+ } |
|
226 |
+ |
|
227 |
+ // Otherwise, assume the configured class has a DateTime compatible constructor... |
|
228 |
+ return new $dateClass($date->format('Y-m-d H:i:s.u'), $date->getTimezone()); |
|
229 |
+ } |
|
230 |
+} |