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