Skip to content

Commit

Permalink
Merge pull request #10 from kylekatarnls/carbon-3
Browse files Browse the repository at this point in the history
Add support for Carbon 3
  • Loading branch information
kylekatarnls authored Jan 3, 2025
2 parents 7bc2d96 + ae0f78e commit 731abb6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ jobs:
path: ~/.composer/cache
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.setup }}-composer-${{ hashFiles('**/composer.lock') }}

- name: Set PHPUnit version
if: matrix.php >= 8.1
run: composer require "phpunit/phpunit:^8.5.41" --no-update

- name: Install Dependencies
run: composer update --prefer-dist --prefer-${{ matrix.setup }} --no-interaction --no-suggest

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"require": {
"php": "^7.1 || ^8.0",
"simple-cli/simple-cli": "^1.1",
"nesbot/carbon": "^2.20"
"nesbot/carbon": "^2.72.6 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5 || ^8.2"
"phpunit/phpunit": "^7.5.20 || ^8.5.41"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 11 additions & 4 deletions src/Carbon/Types/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Carbon\Types;

use Carbon\Carbon;
use Carbon\FactoryImmutable;
use Closure;
use ReflectionClass;
use ReflectionException;
Expand Down Expand Up @@ -51,11 +52,17 @@ protected function getMethods($boots)
$this->runBoot($boot);
}

$c = new ReflectionClass(Carbon::now());
$macros = $c->getProperty('globalMacros');
$macros->setAccessible(true);
if (method_exists(FactoryImmutable::class, 'getDefaultInstance')) {
// Carbon 3
return FactoryImmutable::getDefaultInstance()->getSettings()['macros'] ?? [];
} else {
// Carbon 2
$c = new ReflectionClass(Carbon::now());
$macros = $c->getProperty('globalMacros');
$macros->setAccessible(true);

return $macros->getValue();
return $macros->getValue();
}
}

/**
Expand Down

0 comments on commit 731abb6

Please sign in to comment.