Skip to content

Commit

Permalink
handle doctrine_phpcr in a propper way (#298)
Browse files Browse the repository at this point in the history
* @see #219

* fix bc-break

* fix tests

* fix lint

* check correct doctrine service id for PHPCR

* simulate DoctrinePHPCRBundle is installed in a more saver way (how knows what will come).

* fix lint

Co-authored-by: Volker von Hoeßlin <volker.hoesslin@swsn.de>
  • Loading branch information
skydiablo and Volker von Hoeßlin committed Jun 11, 2021
1 parent 08020ea commit a0f08d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Expand Up @@ -36,7 +36,7 @@ public function process(ContainerBuilder $container): void
$container->removeDefinition('sonata.doctrine.adapter.doctrine_orm');
}

if ($container->has('doctrine_phpcr')) {
if ($this->isDoctrinePHPCRLoaded($container)) {
$definition->addMethodCall('addAdapter', [new Reference('sonata.doctrine.adapter.doctrine_phpcr')]);
} else {
$container->removeDefinition('sonata.doctrine.adapter.doctrine_phpcr');
Expand All @@ -47,4 +47,9 @@ private function isDoctrineOrmLoaded(ContainerBuilder $container): bool
{
return $container->has('doctrine') && $container->has('sonata.doctrine.adapter.doctrine_orm');
}

private function isDoctrinePHPCRLoaded(ContainerBuilder $container): bool
{
return $container->has('doctrine_phpcr') && $container->has('sonata.doctrine.adapter.doctrine_phpcr');
}
}
Expand Up @@ -35,7 +35,8 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('mapper_orm.php');
}

if (class_exists(DocumentManager::class)) {
$bundles = $container->getParameter('kernel.bundles');
if (class_exists(DocumentManager::class) && isset($bundles['DoctrinePHPCRBundle'])) {
$loader->load('doctrine_phpcr.php');
}
}
Expand Down
Expand Up @@ -20,6 +20,14 @@ final class SonataDoctrineExtensionTest extends AbstractExtensionTestCase
{
public function testServicesAreLoaded(): void
{
//simulate DoctrinePHPCRBundle is installed
$kernelBundles = $this->container->getParameterBag()->has('kernel.bundles') ?
(array) $this->container->getParameterBag()->get('kernel.bundles') : [];
$this->container->getParameterBag()->set(
'kernel.bundles',
['DoctrinePHPCRBundle' => true] + $kernelBundles
);

$this->load();

$this->assertContainerBuilderHasService('sonata.doctrine.model.adapter.chain');
Expand Down

0 comments on commit a0f08d8

Please sign in to comment.