Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with doctrine/persistence 2.0 #1332

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions src/DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ class_exists('Sonata\GoogleAuthenticator\GoogleAuthenticator')) {
$container->setParameter('sonata.user.impersonating', $config['impersonating']);

$this->configureGoogleAuthenticator($config, $container);

$this->createDoctrineCommonBackwardCompatibilityAliases();
}

/**
Expand Down Expand Up @@ -371,19 +369,4 @@ private function registerSonataDoctrineMapping(array $config): void
]])
);
}

/**
* We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped
* or adapted to work with "doctrine/common:^3".
*/
private function createDoctrineCommonBackwardCompatibilityAliases(): void
{
if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
}

if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
}
}
}
16 changes: 16 additions & 0 deletions src/SonataUserBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function build(ContainerBuilder $container): void
public function boot(): void
{
$this->registerFormMapping();
$this->createDoctrineCommonBackwardCompatibilityAliases();
}

/**
Expand All @@ -58,4 +59,19 @@ public function registerFormMapping(): void
]);
}
}

/**
* We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped
* or adapted to work with "doctrine/common:^3".
*/
private function createDoctrineCommonBackwardCompatibilityAliases(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making this method public static in order to call it in the custom_boostrap ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it would be bc break to remove it, IMO not a good idea.

{
if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
}

if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
}
}
}
25 changes: 25 additions & 0 deletions tests/custom_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/*
* We MUST remove file this when support for "friendsofsymfony/user-bundle" is dropped
* or adapted to work with "doctrine/common:^3".
*/

if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) {
class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class);
}

if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) {
class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class);
}