Skip to content

Commit

Permalink
Add support for "doctrine/common:^3"
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys authored and greg0ire committed Feb 9, 2021
1 parent da331a3 commit 4f416e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
],
"require": {
"php": "^7.3",
"doctrine/common": "^2.0",
"doctrine/common": "^2.0 || ^3.1",
"doctrine/persistence": "^1.3 || ^2.1",
"friendsofsymfony/user-bundle": "^2.0",
"sonata-project/admin-bundle": "^3.76",
"sonata-project/datagrid-bundle": "^3.0.1",
Expand Down
17 changes: 17 additions & 0 deletions src/DependencyInjection/SonataUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class_exists('Sonata\GoogleAuthenticator\GoogleAuthenticator')) {
$container->setParameter('sonata.user.impersonating', $config['impersonating']);

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

$this->createDoctrineCommonBackwardCompatibilityAliases();
}

/**
Expand Down Expand Up @@ -369,4 +371,19 @@ 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);
}
}
}
4 changes: 1 addition & 3 deletions src/Entity/UserManagerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\UserBundle\Entity;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Sonata\Doctrine\Entity\BaseEntityManager;

/**
Expand All @@ -30,8 +30,6 @@ class UserManagerProxy extends BaseEntityManager
protected $userManager;

/**
* UserManagerProxy constructor.
*
* @param string $class
*/
public function __construct($class, ManagerRegistry $registry, UserManager $userManager)
Expand Down
4 changes: 2 additions & 2 deletions tests/Entity/UserManagerProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\UserBundle\Tests\Entity;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Sonata\UserBundle\Entity\UserManager;
use Sonata\UserBundle\Entity\UserManagerProxy;
Expand All @@ -22,7 +22,7 @@ class UserManagerProxyTest extends TestCase
{
public function testProxy(): void
{
$doctrine = $this->getMockBuilder(ManagerRegistry::class)->disableOriginalConstructor()->getMock();
$doctrine = $this->createStub(ManagerRegistry::class);

$userManager = $this->getMockBuilder(UserManager::class)->disableOriginalConstructor()->getMock();

Expand Down

0 comments on commit 4f416e1

Please sign in to comment.