8000 [DoctrineBridge] try to fix deprecations from doctrine/persistence by nicolas-grekas · Pull Request #34949 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] try to fix deprecations from doctrine/persistence #34949

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

Merged
merged 1 commit into from
Dec 12, 2019
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
8 changes: 6 additions & 2 deletions src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Symfony\Bridge\Doctrine\CacheWarmer;

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

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

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

namespace Symfony\Bridge\Doctrine\DataCollector;

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

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

$mappingDriverDef = $this->getDriver($container);
$chainDriverDefService = $this->getChainDriverServiceName($container);
// Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
// Definition for a Doctrine\Persistence\Mapping\Driver\MappingDriverChain
$chainDriverDef = $container->getDefinition($chainDriverDefService);
foreach ($this->namespaces as $namespace) {
$chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
Expand Down Expand Up @@ -41,11 +42,11 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
* passed which optimizes the object loading for one of the Doctrine
* mapper implementations.
*
* @param ObjectManager $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 ChoiceListFactoryInterface $factory The factory for creating the loaded choice list
* @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 ChoiceListFactoryInterface $factory The factory for creating the loaded choice list
*/
public function __construct($manager, $class, $idReader = null, $objectLoader = null, $factory = null)
{
Expand Down
12 changes: 9 additions & 3 deletions src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bridge\Doctrine\Form\ChoiceList;

use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\Common\Persistence\ObjectManager;
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 @@ -35,7 +37,11 @@ class IdReader
*/
private $associationIdReader;

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

namespace Symfony\Bridge\Doctrine\Form;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractExtension;

class DoctrineOrmExtension extends AbstractExtension
{
protected $registry;

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

namespace Symfony\Bridge\Doctrine\Form;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyCommonMappingException;
use Doctrine\Common\Util\ClassUtils;
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 Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess;
Expand All @@ -28,7 +30,10 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface

private $cache = [];

public function __construct(ManagerRegistry $registry)
/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{
$this->registry = $registry;
}
Expand Down Expand Up @@ -173,6 +178,8 @@ 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 Down
18 changes: 11 additions & 7 deletions src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bridge\Doctrine\Form\Type;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
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;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
10000 Expand Down Expand Up @@ -99,7 +101,10 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder)
return false;
}

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

$emNormalizer = function (Options $options, $em) {
/* @var ManagerRegistry $registry */
if (null !== $em) {
if ($em instanceof ObjectManager) {
if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
return $em;
}

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

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the type would be a BC break

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it really? It's a class alias, so they are the same thing, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not when v1.2 is checked out


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,7 +11,7 @@

namespace Symfony\Bridge\Doctrine\Form\Type;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function configureOptions(OptionsResolver $resolver)
*
* @return ORMQueryBuilderLoader
*/
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the type would be a BC break

{
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;
use Doctrine\Common\Persistence\AbstractManagerRegistry as LegacyAbstractManagerRegistry;
use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
Expand All @@ -22,7 +22,7 @@
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
abstract class ManagerRegistry extends AbstractManagerRegistry implements ContainerAwareInterface
abstract class ManagerRegistry extends LegacyAbstractManagerRegistry implements ContainerAwareInterface
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the type would be a BC break

{
/**
* @var Container
Expand Down
15 changes: 12 additions & 3 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

namespace Symfony\Bridge\Doctrine\PropertyInfo;

use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\MappingException;
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\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\Mapping\MappingException;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Type;
Expand All @@ -29,7 +31,10 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
{
private $classMetadataFactory;

public function __construct(ClassMetadataFactory $classMetadataFactory)
/**
* @param ClassMetadataFactory|LegacyClassMetadataFactory $classMetadataFactory
*/
public function __construct($classMetadataFactory)
{
$this->classMetadataFactory = $classMetadataFactory;
}
Expand All @@ -45,6 +50,8 @@ public function getProperties($class, array $context = [])
return null;
} catch (OrmMappingException $exception) {
return null;
} catch (LegacyMappingException $exception) {
return null;
}

$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
Expand All @@ -71,6 +78,8 @@ public function getTypes($class, $property, array $context = [])
return null;
} catch (OrmMappingException $exception) {
return null;
} catch (LegacyMappingException $exception) {
return null;
}

if ($metadata->hasAssociation($property)) {
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 ManagerRegistryInterface;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\ORM\EntityManager;

/**
* References Doctrine connections and entity managers.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface RegistryInterface extends ManagerRegistryInterface
interface RegistryInterface extends LegacyManagerRegistry
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the type would be a BC break

{
/**
* Gets the default entity manager name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

namespace Symfony\Bridge\Doctrine\Security\User;

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

public function __construct(ManagerRegistry $registry, $classOrAlias, $property = null, $managerName = null)
/**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry, $classOrAlias, $property = null, $managerName = null)
{
$this->registry = $registry;
$this->managerName = $managerName;
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

namespace Symfony\Bridge\Doctrine\Test;

use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Repository\RepositoryFactory;
use Doctrine\Persistence\ObjectRepository;

/**
* @author Andreas Braun <alcaeus@alcaeus.org>
Expand All @@ -40,15 +41,15 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName
return $this->repositoryList[$repositoryHash] = $this->createRepository($entityManager, $entityName);
}

public function setRepository(EntityManagerInterface $entityManager, $entityName, ObjectRepository $repository)
public function setRepository(EntityManagerInterface $entityManager, $entityName, LegacyObjectRepository $repository)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing the type would be a BC break

{
$repositoryHash = $this->getRepositoryHash($entityManager, $entityName);

$this->repositoryList[$repositoryHash] = $repository;
}

/**
* @return ObjectRepository
* @return ObjectRepository|LegacyObjectRepository
*/
private function createRepository(EntityManagerInterface $entityManager, $entityName)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Symfony\Bridge\Doctrine\Tests\DataCollector;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Version;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -180,7 +182,7 @@ private function createCollector($queries)
->method('getDatabasePlatform')
->willReturn(new MySqlPlatform());

$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
$registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$registry
->expects($this->any())
->method('getConnectionNames')
Expand Down
Loading
0