44
55namespace LaravelDoctrine \Extensions ;
66
7- use Gedmo \DoctrineExtensions ;
7+ use Doctrine \Persistence \Mapping \Driver \MappingDriverChain ;
8+ use Illuminate \Contracts \Container \BindingResolutionException ;
89use Illuminate \Support \ServiceProvider ;
10+ use LaravelDoctrine \Fluent \Extensions \GedmoExtensions ;
11+ use LaravelDoctrine \Fluent \FluentDriver ;
912
1013class 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