Skip to content

Commit

Permalink
minor #145 Autowire Doctrine\Persistence\ObjectManager (pamil)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.6 branch.

Discussion
----------

`Doctrine\Common\Persistence\ObjectManager` is now deprecated.

Commits
-------

b26a67b Autowire Doctrine\Persistence\ObjectManager
  • Loading branch information
pamil authored Jan 13, 2020
2 parents a18fd0e + b26a67b commit e696dc2
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\Doctrine;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as DeprecatedObjectManager;
use Doctrine\Persistence\ObjectManager;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Driver\AbstractDriver;
use Sylius\Component\Resource\Metadata\MetadataInterface;
use Symfony\Component\DependencyInjection\Alias;
Expand Down Expand Up @@ -47,11 +48,17 @@ protected function addManager(ContainerBuilder $container, MetadataInterface $me

/** @psalm-suppress RedundantCondition Backward compatibility with Symfony */
if (method_exists($container, 'registerAliasForArgument')) {
$container->registerAliasForArgument(
$metadata->getServiceId('manager'),
ObjectManager::class,
$metadata->getHumanizedName() . ' manager'
);
foreach ([DeprecatedObjectManager::class, ObjectManager::class] as $objectManagerClass) {
if (!class_exists($objectManagerClass)) {
continue;
}

$container->registerAliasForArgument(
$metadata->getServiceId('manager'),
$objectManagerClass,
$metadata->getHumanizedName() . ' manager'
);
}
}
}

Expand Down

0 comments on commit e696dc2

Please sign in to comment.