|
8 | 8 | use Illuminate\Filesystem\Filesystem;
|
9 | 9 | use Illuminate\Routing\Router;
|
10 | 10 | use Illuminate\Support\Arr;
|
| 11 | +use Illuminate\Support\Facades\Date; |
11 | 12 | use League\Flysystem\Filesystem as Flysystem;
|
12 | 13 | use League\Flysystem\Local\LocalFilesystemAdapter;
|
| 14 | +use ReflectionClass; |
13 | 15 | use Statamic\Contracts\Imaging\UrlBuilder;
|
14 | 16 | use Statamic\Facades\Blink;
|
15 | 17 | use Statamic\Facades\Collection;
|
@@ -266,8 +268,7 @@ protected function makeContentGenerationClosures($pages, $request)
|
266 | 268 | $errors = [];
|
267 | 269 |
|
268 | 270 | foreach ($pages as $page) {
|
269 |
| - // There is no getter method, so use reflection. |
270 |
| - $oldCarbonFormat = (new \ReflectionClass(Carbon::class))->getStaticPropertyValue('toStringFormat'); |
| 271 | + $oldCarbonFormat = $this->getToStringFormat(); |
271 | 272 |
|
272 | 273 | if ($this->shouldSetCarbonFormat($page)) {
|
273 | 274 | Carbon::setToStringFormat(Statamic::dateFormat());
|
@@ -481,4 +482,29 @@ protected function shouldRejectPage($page, $outputError = false)
|
481 | 482 |
|
482 | 483 | return $excluded;
|
483 | 484 | }
|
| 485 | + |
| 486 | + /** |
| 487 | + * This method is used to get the current toStringFormat for Carbon, in order for us |
| 488 | + * to restore it later. There's no getter for it, so we need to use reflection. |
| 489 | + * |
| 490 | + * @throws \ReflectionException |
| 491 | + */ |
| 492 | + protected function getToStringFormat(): ?string |
| 493 | + { |
| 494 | + $reflection = new ReflectionClass($date = Date::now()); |
| 495 | + |
| 496 | + // Carbon 2.x |
| 497 | + if ($reflection->hasProperty('toStringFormat')) { |
| 498 | + $format = $reflection->getProperty('toStringFormat'); |
| 499 | + $format->setAccessible(true); |
| 500 | + |
| 501 | + return $format->getValue(); |
| 502 | + } |
| 503 | + |
| 504 | + // Carbon 3.x |
| 505 | + $factory = $reflection->getMethod('getFactory'); |
| 506 | + $factory->setAccessible(true); |
| 507 | + |
| 508 | + return Arr::get($factory->invoke($date)->getSettings(), 'toStringFormat'); |
| 509 | + } |
484 | 510 | }
|
0 commit comments