Skip to content
This repository was archived by the owner on Sep 8, 2023. It is now read-only.

Commit 29e44b3

Browse files
authored
Fix compatibility with Carbon >= 1.26
Carbon implements macros on its own since 1.26.2 and use $globalMacros property to avoid conflict with Laravel layer. Macros are also implemented on other classes of the root namespace (CarbonInterval, CarbonPeriod and CarbonImmutable introduced in 2.0)
1 parent 424453b commit 29e44b3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Console/MacrosCommand.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class MacrosCommand extends Command
1717
'\Illuminate\Database\Schema\Blueprint',
1818
'\Illuminate\Support\Arr',
1919
'\Illuminate\Support\Carbon',
20+
'\Carbon\Carbon',
21+
'\Carbon\CarbonImmutable',
22+
'\Carbon\CarbonInterval',
23+
'\Carbon\CarbonPeriod',
2024
'\Illuminate\Support\Collection',
2125
'\Illuminate\Console\Scheduling\Event',
2226
'\Illuminate\Database\Eloquent\FactoryBuilder',
@@ -66,11 +70,15 @@ public function handle()
6670
}
6771

6872
$reflection = new \ReflectionClass($class);
69-
if (!$reflection->hasProperty('macros')) {
70-
continue;
73+
$propertyName = 'macros';
74+
if (!$reflection->hasProperty($propertyName)) {
75+
$propertyName = 'globalMacros';
76+
if (!$reflection->hasProperty($propertyName)) {
77+
continue;
78+
}
7179
}
7280

73-
$property = $reflection->getProperty('macros');
81+
$property = $reflection->getProperty($propertyName);
7482
$property->setAccessible(true);
7583
$macros = $property->getValue();
7684

0 commit comments

Comments
 (0)