Skip to content

Commit 731abb6

Browse files
authored
Merge pull request #10 from kylekatarnls/carbon-3
Add support for Carbon 3
2 parents 7bc2d96 + ae0f78e commit 731abb6

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.github/workflows/tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ jobs:
3939
path: ~/.composer/cache
4040
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.setup }}-composer-${{ hashFiles('**/composer.lock') }}
4141

42+
- name: Set PHPUnit version
43+
if: matrix.php >= 8.1
44+
run: composer require "phpunit/phpunit:^8.5.41" --no-update
45+
4246
- name: Install Dependencies
4347
run: composer update --prefer-dist --prefer-${{ matrix.setup }} --no-interaction --no-suggest
4448

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
"require": {
1515
"php": "^7.1 || ^8.0",
1616
"simple-cli/simple-cli": "^1.1",
17-
"nesbot/carbon": "^2.20"
17+
"nesbot/carbon": "^2.72.6 || ^3.0"
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^7.5 || ^8.2"
20+
"phpunit/phpunit": "^7.5.20 || ^8.5.41"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/Carbon/Types/Generator.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Carbon\Types;
44

55
use Carbon\Carbon;
6+
use Carbon\FactoryImmutable;
67
use Closure;
78
use ReflectionClass;
89
use ReflectionException;
@@ -51,11 +52,17 @@ protected function getMethods($boots)
5152
$this->runBoot($boot);
5253
}
5354

54-
$c = new ReflectionClass(Carbon::now());
55-
$macros = $c->getProperty('globalMacros');
56-
$macros->setAccessible(true);
55+
if (method_exists(FactoryImmutable::class, 'getDefaultInstance')) {
56+
// Carbon 3
57+
return FactoryImmutable::getDefaultInstance()->getSettings()['macros'] ?? [];
58+
} else {
59+
// Carbon 2
60+
$c = new ReflectionClass(Carbon::now());
61+
$macros = $c->getProperty('globalMacros');
62+
$macros->setAccessible(true);
5763

58-
return $macros->getValue();
64+
return $macros->getValue();
65+
}
5966
}
6067

6168
/**

0 commit comments

Comments
 (0)