Skip to content

Commit a6f571f

Browse files
authored
Merge pull request #87 from TomHAnderson/ENG-10137_doctrine-3.1-compatibility
Eng 10137 doctrine 3.1 compatibility
2 parents 4bfe9b6 + de9593c commit a6f571f

File tree

6 files changed

+65
-13
lines changed

6 files changed

+65
-13
lines changed

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ on:
1313
jobs:
1414
coding-standards:
1515
name: "Coding Standards"
16-
uses: "doctrine/.github/.github/workflows/coding-standards.yml@1.3.0"
16+
uses: "doctrine/.github/.github/workflows/coding-standards.yml@5.2.0"
1717
with:
1818
php-version: '8.2'
1919
composer-options: '--prefer-dist --ignore-platform-req=php'
20-

.github/workflows/continuous-integration.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
jobs:
1414
phpunit:
1515
name: "PHPUnit"
16-
runs-on: "ubuntu-20.04"
16+
runs-on: "ubuntu-latest"
1717

1818
strategy:
1919
fail-fast: false
@@ -62,22 +62,22 @@ jobs:
6262

6363
upload_coverage:
6464
name: "Upload coverage to Codecov"
65-
runs-on: "ubuntu-20.04"
65+
runs-on: "ubuntu-latest"
6666
needs:
6767
- "phpunit"
6868

6969
steps:
7070
- name: "Checkout"
71-
uses: "actions/checkout@v2"
71+
uses: "actions/checkout@v6"
7272
with:
7373
fetch-depth: 2
7474

7575
- name: "Download coverage files"
76-
uses: "actions/download-artifact@v4"
76+
uses: "actions/download-artifact@v5"
7777
with:
7878
path: "reports"
7979

8080
- name: "Upload to Codecov"
81-
uses: "codecov/codecov-action@v2"
81+
uses: "codecov/codecov-action@v5"
8282
with:
8383
directory: "reports"

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
php-version:
1515
- "8.2"
1616
- "8.3"
17+
- "8.4"
18+
- "8.5"
1719

1820
steps:
1921
- name: "Checkout code"

phpstan-baseline.neon

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Call to static method registerAbstract\(\) on an unknown class LaravelDoctrine\\Fluent\\Extensions\\GedmoExtensions\.$#'
5+
identifier: class.notFound
6+
count: 1
7+
path: src/GedmoExtensionsServiceProvider.php
8+
9+
-
10+
message: '#^Call to static method registerAll\(\) on an unknown class LaravelDoctrine\\Fluent\\Extensions\\GedmoExtensions\.$#'
11+
identifier: class.notFound
12+
count: 1
13+
path: src/GedmoExtensionsServiceProvider.php
14+
15+
-
16+
message: '#^Class LaravelDoctrine\\Fluent\\FluentDriver not found\.$#'
17+
identifier: class.notFound
18+
count: 1
19+
path: src/GedmoExtensionsServiceProvider.php

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
4+
parameters:
5+
level: 7
6+
paths:
7+
- src

src/GedmoExtensionsServiceProvider.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
namespace LaravelDoctrine\Extensions;
66

7-
use Gedmo\DoctrineExtensions;
7+
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
8+
use Illuminate\Contracts\Container\BindingResolutionException;
89
use Illuminate\Support\ServiceProvider;
10+
use LaravelDoctrine\Fluent\Extensions\GedmoExtensions;
11+
use LaravelDoctrine\Fluent\FluentDriver;
912

1013
class GedmoExtensionsServiceProvider extends ServiceProvider
1114
{
@@ -20,16 +23,38 @@ public function register(): void
2023
foreach ($registry->getManagers() as $manager) {
2124
$chain = $manager->getConfiguration()->getMetadataDriverImpl();
2225

23-
if ($this->needsAllMappings()) {
24-
DoctrineExtensions::registerMappingIntoDriverChainORM($chain);
25-
} else {
26-
DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($chain);
26+
if (! $this->hasFluentDriver($chain)) {
27+
continue;
2728
}
29+
30+
$this->registerGedmoForFluent($chain);
2831
}
2932
});
3033
}
3134

32-
private function needsAllMappings(): mixed
35+
private function hasFluentDriver(MappingDriverChain $driver): bool
36+
{
37+
foreach ($driver->getDrivers() as $driver) {
38+
if ($driver instanceof FluentDriver) {
39+
return true;
40+
}
41+
}
42+
43+
return false;
44+
}
45+
46+
/** @throws BindingResolutionException */
47+
private function registerGedmoForFluent(MappingDriverChain $chain): void
48+
{
49+
if ($this->needsAllMappings()) {
50+
GedmoExtensions::registerAll($chain);
51+
} else {
52+
GedmoExtensions::registerAbstract($chain);
53+
}
54+
}
55+
56+
/** @throws BindingResolutionException */
57+
private function needsAllMappings(): bool
3358
{
3459
return $this->app->make('config')->get('doctrine.gedmo.all_mappings', false) === true;
3560
}

0 commit comments

Comments
 (0)