Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.

Commit

Permalink
Support doctrine/persistence v2
Browse files Browse the repository at this point in the history
  • Loading branch information
scheb committed Jun 3, 2020
1 parent 5e12d43 commit 37ec5f0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
9 changes: 6 additions & 3 deletions Model/Persister/DoctrinePersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

namespace Scheb\TwoFactorBundle\Model\Persister;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ObjectManager;
use Scheb\TwoFactorBundle\Model\PersisterInterface;

class DoctrinePersister implements PersisterInterface
{
/**
* @var ObjectManager
* @var ObjectManager|LegacyObjectManager
*/
private $om;

/**
* Initialize a persister for doctrine entities.
*
* @param ObjectManager|LegacyObjectManager $om
*/
public function __construct(ObjectManager $om)
public function __construct($om)
{
$this->om = $om;
}
Expand Down
14 changes: 8 additions & 6 deletions Model/Persister/DoctrinePersisterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

namespace Scheb\TwoFactorBundle\Model\Persister;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Scheb\TwoFactorBundle\Model\PersisterInterface;

class DoctrinePersisterFactory
{
/**
* @var ManagerRegistry
* @var ManagerRegistry|LegacyManagerRegistry
*/
private $managerRegistry;

Expand All @@ -19,7 +20,10 @@ class DoctrinePersisterFactory
*/
private $objectManagerName;

public function __construct(?ManagerRegistry $managerRegistry, ?string $objectManagerName)
/**
* @param ManagerRegistry|LegacyManagerRegistry|null $managerRegistry
*/
public function __construct($managerRegistry, ?string $objectManagerName)
{
if (!$managerRegistry) {
$msg = 'scheb/two-factor-bundle requires Doctrine to manage the user entity. If you don\'t want something else ';
Expand All @@ -34,9 +38,7 @@ public function __construct(?ManagerRegistry $managerRegistry, ?string $objectMa
public function getPersister(): PersisterInterface
{
$objectManager = $this->managerRegistry->getManager($this->objectManagerName);
/** @psalm-suppress ArgumentTypeCoercion */
$persister = new DoctrinePersister($objectManager);

return $persister;
return new DoctrinePersister($objectManager);
}
}
4 changes: 2 additions & 2 deletions Tests/Model/Persister/DoctrinePersisterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Scheb\TwoFactorBundle\Tests\Model\Persister;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Scheb\TwoFactorBundle\Model\Persister\DoctrinePersister;
use Scheb\TwoFactorBundle\Model\Persister\DoctrinePersisterFactory;
use Scheb\TwoFactorBundle\Tests\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Model/Persister/DoctrinePersisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Scheb\TwoFactorBundle\Tests\Model\Persister;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use Scheb\TwoFactorBundle\Model\Persister\DoctrinePersister;
use Scheb\TwoFactorBundle\Tests\TestCase;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"paragonie/constant_time_encoding": "^2.2"
},
"require-dev": {
"doctrine/persistence": "^1.3",
"doctrine/persistence": "^1.3|^2.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0",
"swiftmailer/swiftmailer": "^6.0",
"symfony/yaml": "^3.4|^4.0|^5.0",
Expand Down
14 changes: 14 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,19 @@
<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedTrait errorLevel="info" />
<UndefinedClass>
<!-- BC layer for doctrine/persistence 1.3 -->
<errorLevel type="info">
<referencedClass name="Doctrine\Common\Persistence\ObjectManager"/>
<referencedClass name="Doctrine\Common\Persistence\ManagerRegistry"/>
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
<!-- BC layer for doctrine/persistence 1.3 -->
<errorLevel type="info">
<referencedClass name="Doctrine\Common\Persistence\ObjectManager"/>
<referencedClass name="Doctrine\Common\Persistence\ManagerRegistry"/>
</errorLevel>
</UndefinedDocblockClass>
</issueHandlers>
</psalm>

0 comments on commit 37ec5f0

Please sign in to comment.