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

Add support for "doctrine/persistence:^2.1" #193

Merged
merged 1 commit into from
Feb 17, 2021
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
2 changes: 1 addition & 1 deletion DependencyInjection/Compiler/DoctrineOrmMappingsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Hackzilla\Bundle\TicketBundle\DependencyInjection\Compiler;

use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
use Hackzilla\Bundle\TicketBundle\DependencyInjection\HackzillaTicketExtension;
use Hackzilla\Bundle\TicketBundle\Entity\Ticket;
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
Expand Down
19 changes: 19 additions & 0 deletions DependencyInjection/HackzillaTicketExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function load(array $configs, ContainerBuilder $container)
}

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

if (isset($bundles['FOSUserBundle'])) {
$this->createDoctrineCommonBackwardCompatibilityAliases();
}
}

public static function bundleDirectory()
Expand All @@ -74,4 +78,19 @@ private function setTranslationDomain(array $config, ContainerBuilder $container
$definition = $container->getDefinition('hackzilla_ticket.ticket_manager');
$definition->addMethodCall('setTranslationDomain', [$translationDomain]);
}

/**
* 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: 14 additions & 2 deletions Manager/TicketManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Hackzilla\Bundle\TicketBundle\Manager;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ObjectManager;
use Hackzilla\Bundle\TicketBundle\Entity\TicketMessage;
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
Expand Down Expand Up @@ -54,10 +55,21 @@ public function __construct($ticketClass, $ticketMessageClass)
$this->ticketMessageClass = $ticketMessageClass;
}

public function setObjectManager(ObjectManager $objectManager): void
{
$this->objectManager = $objectManager;
$this->ticketRepository = $objectManager->getRepository($this->ticketClass);
$this->messageRepository = $objectManager->getRepository($this->ticketMessageClass);
}

/**
* NEXT_MAJOR: Remove this method.
*
* @deprecated since hackzilla/ticket-bundle 3.x, use `setObjectManager()` instead.
*
* @return $this
*/
public function setEntityManager(ObjectManager $om)
public function setEntityManager(LegacyObjectManager $om)
{
$this->objectManager = $om;
$this->ticketRepository = $om->getRepository($this->ticketClass);
Expand Down
9 changes: 7 additions & 2 deletions Manager/TicketManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@

namespace Hackzilla\Bundle\TicketBundle\Manager;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectManager;
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
use Symfony\Component\Translation\TranslatorInterface;

/**
* @method QueryBuilder getTicketListQuery(UserManagerInterface $userManager, $ticketStatus, $ticketPriority = null)
* @method void setObjectManager(ObjectManager $objectManager)
*/
interface TicketManagerInterface
{
public function setEntityManager(ObjectManager $om);
/**
* @deprecated since hackzilla/ticket-bundle 3.x, use `setObjectManager()` instead.
*/
public function setEntityManager(LegacyObjectManager $om);

public function setTranslator(TranslatorInterface $translator);

Expand Down
2 changes: 1 addition & 1 deletion Manager/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Hackzilla\Bundle\TicketBundle\Manager;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\Persistence\ObjectRepository;
use Hackzilla\Bundle\TicketBundle\Model\TicketInterface;
use Hackzilla\Bundle\TicketBundle\Model\UserInterface;
use Hackzilla\Bundle\TicketBundle\TicketRole;
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- '%hackzilla_ticket.model.ticket.class%'
- '%hackzilla_ticket.model.message.class%'
calls:
- [ setEntityManager, ['@doctrine.orm.entity_manager'] ]
- [ setObjectManager, ['@doctrine.orm.entity_manager'] ]
- [ setTranslator, ['@translator'] ]
public: true

Expand Down
6 changes: 3 additions & 3 deletions Tests/Manager/TicketManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Hackzilla\Bundle\TicketBundle\Tests\User;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectManager;
use Hackzilla\Bundle\TicketBundle\Manager\TicketManager;
use Hackzilla\Bundle\TicketBundle\Manager\UserManagerInterface;
use Hackzilla\Bundle\TicketBundle\Model\TicketMessageInterface;
Expand Down Expand Up @@ -65,7 +65,7 @@ public function testGetTicketListQuery()
->willReturn($entityRepository);

$ticketManager = new TicketManager($ticketClass, $ticketMessageClass);
$ticketManager->setEntityManager($om);
$ticketManager->setObjectManager($om);

$this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketListQuery($this->userManager, TicketMessageInterface::STATUS_OPEN));
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public function testGetTicketList()
->willReturn($entityRepository);

$ticketManager = new TicketManager($ticketClass, $ticketMessageClass);
$ticketManager->setEntityManager($om);
$ticketManager->setObjectManager($om);

$this->assertInstanceOf(QueryBuilder::class, $ticketManager->getTicketList($this->userManager, TicketMessageInterface::STATUS_OPEN));
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"doctrine/collections": "^1.6",
"doctrine/doctrine-bundle": "^2.0",
"doctrine/orm": "^2.4.8",
"doctrine/persistence": "^1.3",
"doctrine/persistence": "^1.3 || ^2.1",
"knplabs/knp-paginator-bundle": "^4.0 || ^5.0",
"symfony/config": "^4.4",
"symfony/console": "^4.4",
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ parameters:
- Tests/
ignoreErrors:
- '#.* (class|type) Vich\\UploaderBundle\\.*#'
- '#^Class Doctrine\\Common\\Persistence\\ObjectManager not found\.$#'
- '#^Class Doctrine\\Common\\Persistence\\Event\\LifecycleEventArgs not found\.$#'
- '#^Parameter \$om of method Hackzilla\\Bundle\\TicketBundle\\Manager\\TicketManager(Interface)?::setEntityManager\(\) has invalid typehint type Doctrine\\Common\\Persistence\\ObjectManager\.$#'