Skip to content

Commit

Permalink
Require doctrine/persistence ^1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 12, 2019
1 parent 80d15cd commit 7af8eda
Show file tree
Hide file tree
Showing 30 changed files with 66 additions and 134 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": "^7.1.3",
"ext-xml": "*",
"doctrine/event-manager": "~1.0",
"doctrine/persistence": "~1.0",
"doctrine/persistence": "^1.3",
"fig/link-util": "^1.0",
"twig/twig": "^1.41|^2.10",
"psr/cache": "~1.0",
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\CacheWarmer;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

Expand All @@ -27,10 +26,7 @@ class ProxyCacheWarmer implements CacheWarmerInterface
{
private $registry;

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\DataCollector;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type;
Expand All @@ -36,10 +35,7 @@ class DoctrineDataCollector extends DataCollector
*/
private $loggers = [];

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
$this->connections = $registry->getConnectionNames();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
Expand Down Expand Up @@ -41,12 +40,11 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
* passed which optimizes the object loading for one of the Doctrine
* mapper implementations.
*
* @param ObjectManager|LegacyObjectManager $manager The object manager
* @param string $class The class name of the loaded objects
* @param IdReader $idReader The reader for the object IDs
* @param EntityLoaderInterface|null $objectLoader The objects loader
* @param string $class The class name of the loaded objects
* @param IdReader $idReader The reader for the object IDs
* @param EntityLoaderInterface|null $objectLoader The objects loader
*/
public function __construct($manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
{
$classMetadata = $manager->getClassMetadata($class);

Expand Down
8 changes: 1 addition & 7 deletions src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\Exception\RuntimeException;
Expand All @@ -37,11 +35,7 @@ class IdReader
*/
private $associationIdReader;

/**
* @param ObjectManager|LegacyObjectManager $om
* @param ClassMetadata|LegacyClassMetadata $classMetadata
*/
public function __construct($om, $classMetadata)
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
{
$ids = $classMetadata->getIdentifierFieldNames();
$idType = $classMetadata->getTypeOfField(current($ids));
Expand Down
6 changes: 1 addition & 5 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bridge\Doctrine\Form;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractExtension;
Expand All @@ -20,10 +19,7 @@ class DoctrineOrmExtension extends AbstractExtension
{
protected $registry;

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
Expand Down
17 changes: 4 additions & 13 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@

namespace Symfony\Bridge\Doctrine\Form;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyCommonMappingException;
use Doctrine\Common\Persistence\Proxy;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\MappingException;
use Doctrine\Persistence\Proxy;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;
Expand All @@ -30,10 +28,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface

private $cache = [];

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
Expand Down Expand Up @@ -187,8 +182,6 @@ protected function getMetadata($class)
return $this->cache[$class] = [$em->getClassMetadata($class), $name];
} catch (MappingException $e) {
// not an entity or mapped super class
} catch (LegacyCommonMappingException $e) {
// not an entity or mapped super class
} catch (LegacyMappingException $e) {
// not an entity or mapped super class, using Doctrine ORM 2.2
}
Expand All @@ -199,12 +192,10 @@ protected function getMetadata($class)

private static function getRealClass(string $class): string
{
$marker = interface_exists(Proxy::class) ? '\\'.Proxy::MARKER.'\\' : '\__CG__\\';

if (false === $pos = strrpos($class, $marker)) {
if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
return $class;
}

return substr($class, $pos + \strlen($marker));
return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
}
}
13 changes: 4 additions & 9 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
namespace Symfony\Bridge\Doctrine\Form\Type;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
Expand Down Expand Up @@ -103,10 +101,7 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder)
return false;
}

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
Expand Down Expand Up @@ -197,7 +192,7 @@ public function configureOptions(OptionsResolver $resolver)

$emNormalizer = function (Options $options, $em) {
if (null !== $em) {
if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
if ($em instanceof ObjectManager) {
return $em;
}

Expand Down Expand Up @@ -267,7 +262,7 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
$resolver->setNormalizer('id_reader', $idReaderNormalizer);

$resolver->setAllowedTypes('em', ['null', 'string', ObjectManager::class, LegacyObjectManager::class]);
$resolver->setAllowedTypes('em', ['null', 'string', ObjectManager::class]);
}

/**
Expand All @@ -278,7 +273,7 @@ public function configureOptions(OptionsResolver $resolver)
*
* @return EntityLoaderInterface
*/
abstract public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class);
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);

public function getParent()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace Symfony\Bridge\Doctrine\Form\Type;

use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\OptionsResolver\Options;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function configureOptions(OptionsResolver $resolver)
*
* @return ORMQueryBuilderLoader
*/
public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class)
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
{
return new ORMQueryBuilderLoader($queryBuilder);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/ManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Bridge\Doctrine;

use Doctrine\Common\Persistence\AbstractManagerRegistry as LegacyAbstractManagerRegistry;
use Doctrine\Persistence\AbstractManagerRegistry;
use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Component\DependencyInjection\Container;

Expand All @@ -20,7 +20,7 @@
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
abstract class ManagerRegistry extends LegacyAbstractManagerRegistry
abstract class ManagerRegistry extends AbstractManagerRegistry
{
/**
* @var Container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Bridge\Doctrine\PropertyInfo;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as LegacyClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyMappingException;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -42,7 +40,7 @@ public function __construct($entityManager)
{
if ($entityManager instanceof EntityManagerInterface) {
$this->entityManager = $entityManager;
} elseif ($entityManager instanceof ClassMetadataFactory || $entityManager instanceof LegacyClassMetadataFactory) {
} elseif ($entityManager instanceof ClassMetadataFactory) {
@trigger_error(sprintf('Injecting an instance of "%s" in "%s" is deprecated since Symfony 4.2, inject an instance of "%s" instead.', ClassMetadataFactory::class, __CLASS__, EntityManagerInterface::class), E_USER_DEPRECATED);
$this->classMetadataFactory = $entityManager;
} else {
Expand Down Expand Up @@ -202,7 +200,7 @@ private function getMetadata(string $class): ?ClassMetadata
{
try {
return $this->entityManager ? $this->entityManager->getClassMetadata($class) : $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException | OrmMappingException | LegacyMappingException $exception) {
} catch (MappingException | OrmMappingException $exception) {
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/RegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace Symfony\Bridge\Doctrine;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\ORM\EntityManager;
use Doctrine\Persistence\ManagerRegistry;

/**
* References Doctrine connections and entity managers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface RegistryInterface extends LegacyManagerRegistry
interface RegistryInterface extends ManagerRegistry
{
/**
* Gets the default entity manager name.
Expand Down
17 changes: 8 additions & 9 deletions src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bridge\Doctrine\Security\User;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
Expand All @@ -34,10 +36,7 @@ class EntityUserProvider implements UserProviderInterface
private $class;
private $property;

/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry, string $classOrAlias, string $property = null, string $managerName = null)
public function __construct(ManagerRegistry $registry, string $classOrAlias, string $property = null, string $managerName = null)
{
$this->registry = $registry;
$this->managerName = $managerName;
Expand Down Expand Up @@ -107,17 +106,17 @@ public function supportsClass($class)
return $class === $this->getClass() || is_subclass_of($class, $this->getClass());
}

private function getObjectManager()
private function getObjectManager(): ObjectManager
{
return $this->registry->getManager($this->managerName);
}

private function getRepository()
private function getRepository(): ObjectRepository
{
return $this->getObjectManager()->getRepository($this->classOrAlias);
}

private function getClass()
private function getClass(): string
{
if (null === $this->class) {
$class = $this->classOrAlias;
Expand All @@ -132,7 +131,7 @@ private function getClass()
return $this->class;
}

private function getClassMetadata()
private function getClassMetadata(): ClassMetadata
{
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain as LegacyMappingDriverChain;
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator as LegacySymfonyFileLocator;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
Expand Down Expand Up @@ -76,13 +74,11 @@ public static function createTestConfiguration()
public static function createTestConfigurationWithXmlLoader()
{
$config = static::createTestConfiguration();
$symfonyFileLocator = class_exists(SymfonyFileLocator::class) ? SymfonyFileLocator::class : LegacySymfonyFileLocator::class;
$driverChain = class_exists(MappingDriverChain::class) ? MappingDriverChain::class : LegacyMappingDriverChain::class;

$driverChain = new $driverChain();
$driverChain = new MappingDriverChain();
$driverChain->addDriver(
new XmlDriver(
new $symfonyFileLocator(
new SymfonyFileLocator(
[__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml'
)
),
Expand Down

0 comments on commit 7af8eda

Please sign in to comment.