8000 minor #34949 [DoctrineBridge] try to fix deprecations from doctrine/p… · symfony/symfony@cff8b25 · GitHub
[go: up one dir, main page]

Skip to content

Commit cff8b25

Browse files
minor #34949 [DoctrineBridge] try to fix deprecations from doctrine/persistence (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [DoctrineBridge] try to fix deprecations from doctrine/persistence | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Follows doctrine/persistence#71 But the BC layer is not working yet, as highlighted by the `XXX` in the attached patch. At least for the corresponding interfaces, doctrine/persistence should always alias the legacy name to the new one. /cc @greg0ire @alcaeus FYI Commits ------- 53a4711 [DoctrineBridge] try to fix deprecations from doctrine/persistence
2 parents 349ea04 + 53a4711 commit cff8b25

28 files changed

+151
-77
lines changed

src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bridge\Doctrine\CacheWarmer;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Persistence\ManagerRegistry;
1516
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
1617

1718
/**
@@ -26,7 +27,10 @@ class ProxyCacheWarmer implements CacheWarmerInterface
2627
{
2728
private $registry;
2829

29-
public function __construct(ManagerRegistry $registry)
30+
/**
31+
* @param ManagerRegistry|LegacyManagerRegistry $registry
32+
*/
33+
public function __construct($registry)
3034
{
3135
$this->registry = $registry;
3236
}

src/Symfony/Bridge/Doctrine/DataCollector/DoctrineDataCollector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Bridge\Doctrine\DataCollector;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
1515
use Doctrine\DBAL\Logging\DebugStack;
1616
use Doctrine\DBAL\Types\ConversionException;
1717
use Doctrine\DBAL\Types\Type;
18+
use Doctrine\Persistence\ManagerRegistry;
1819
use Symfony\Component\HttpFoundation\Request;
1920
use Symfony\Component\HttpFoundation\Response;
2021
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
@@ -35,7 +36,10 @@ class DoctrineDataCollector extends DataCollector
3536
*/
3637
private $loggers = [];
3738

38-
public function __construct(ManagerRegistry $registry)
39+
/**
40+
* @param ManagerRegistry|LegacyManagerRegistry $registry
41+
*/
42+
public function __construct($registry)
3943
{
4044
$this->registry = $registry;
4145
$this->connections = $registry->getConnectionNames();

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function process(ContainerBuilder $container)
143143

144144
$mappingDriverDef = $this->getDriver($container);
145145
$chainDriverDefService = $this->getChainDriverServiceName($container);
146-
// Definition for a Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain
146+
// Definition for a Doctrine\Persistence\Mapping\Driver\MappingDriverChain
147147
$chainDriverDef = $container->getDefinition($chainDriverDefService);
148148
foreach ($this->namespaces as $namespace) {
149149
$chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);

src/Symfony/Bridge/Doctrine/Form/ChoiceList/DoctrineChoiceLoader.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

14-
use Doctrine\Common\Persistence\ObjectManager;
14+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
15+
use Doctrine\Persistence\ObjectManager;
1516
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
1617
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1718
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
@@ -41,11 +42,11 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
4142
* passed which optimizes the object loading for one of the Doctrine
4243
* mapper implementations.
4344
*
44-
* @param ObjectManager $manager The object manager
45-
* @param string $class The class name of the loaded objects
46-
* @param IdReader $idReader The reader for the object IDs
47-
* @param EntityLoaderInterface|null $objectLoader The objects loader
48-
* @param ChoiceListFactoryInterface $factory The factory for creating the loaded choice list
45+
* @param ObjectManager|LegacyObjectManager $manager The object manager
46+
* @param string $class The class name of the loaded objects
47+
* @param IdReader $idReader The reader for the object IDs
48+
* @param EntityLoaderInterface|null $objectLoader The objects loader
49+
* @param ChoiceListFactoryInterface $factory The factory for creating the loaded choice list
4950
*/
5051
public function __construct($manager, $class, $idReader = null, $objectLoader = null, $factory = null)
5152
{

src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
1313

14-
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
15-
use Doctrine\Common\Persistence\ObjectManager;
14+
use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
15+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
16+
use Doctrine\Persistence\Mapping\ClassMetadata;
17+
use Doctrine\Persistence\ObjectManager;
1618
use Symfony\Component\Form\Exception\RuntimeException;
1719

1820
/**
@@ -35,7 +37,11 @@ class IdReader
3537
*/
3638
private $associationIdReader;
3739

38-
public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
40+
/**
41+
* @param ObjectManager|LegacyObjectManager $om
42+
* @param ClassMetadata|LegacyClassMetadata $classMetadata
43+
*/
44+
public function __construct($om, $classMetadata)
3945
{
4046
$ids = $classMetadata->getIdentifierFieldNames();
4147
$idType = $classMetadata->getTypeOfField(current($ids));

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Persistence\ManagerRegistry;
1516
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
1617
use Symfony\Component\Form\AbstractExtension;
1718

1819
class DoctrineOrmExtension extends AbstractExtension
1920
{
2021
protected $registry;
2122

22-
public function __construct(ManagerRegistry $registry)
23+
/**
24+
* @param ManagerRegistry|LegacyManagerRegistry $registry
25+
*/
26+
public function __construct($registry)
2327
{
2428
$this->registry = $registry;
2529
}

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Doctrine\Common\Persistence\Mapping\MappingException;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyCommonMappingException;
1616
use Doctrine\Common\Util\ClassUtils;
1717
use Doctrine\DBAL\Types\Type;
1818
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1919
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
20+
use Doctrine\Persistence\ManagerRegistry;
21+
use Doctrine\Persistence\Mapping\MappingException;
2022
use Symfony\Component\Form\FormTypeGuesserInterface;
2123
use Symfony\Component\Form\Guess\Guess;
2224
use Symfony\Component\Form\Guess\TypeGuess;
@@ -28,7 +30,10 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
2830

2931
private $cache = [];
3032

31-
public function __construct(ManagerRegistry $registry)
33+
/**
34+
* @param ManagerRegistry|LegacyManagerRegistry $registry
35+
*/
36+
public function __construct($registry)
3237
{
3338
$this->registry = $registry;
3439
}
@@ -173,6 +178,8 @@ protected function getMetadata($class)
173178
return $this->cache[$class] = [$em->getClassMetadata($class), $name];
174179
} catch (MappingException $e) {
175180
// not an entity or mapped super class
181+
} catch (LegacyCommonMappingException $e) {
182+
// not an entity or mapped super class
176183
} catch (LegacyMappingException $e) {
177184
// not an entity or mapped super class, using Doctrine ORM 2.2
178185
}

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
15-
use Doctrine\Common\Persistence\ObjectManager;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
16+
use Doctrine\Persistence\ManagerRegistry;
17+
use Doctrine\Persistence\ObjectManager;
1618
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1719
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
1820
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@@ -99,7 +101,10 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder)
99101
return false;
100102
}
101103

102-
public function __construct(ManagerRegistry $registry)
104+
/**
105+
* @param ManagerRegistry|LegacyManagerRegistry $registry
106+
*/
107+
public function __construct($registry)
103108
{
104109
$this->registry = $registry;
105110
}
@@ -194,9 +199,8 @@ public function configureOptions(OptionsResolver $resolver)
194199
};
195200

196201
$emNormalizer = function (Options $options, $em) {
197-
/* @var ManagerRegistry $registry */
198202
if (null !== $em) {
199-
if ($em instanceof ObjectManager) {
203+
if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
200204
return $em;
201205
}
202206

@@ -262,7 +266,7 @@ public function configureOptions(OptionsResolver $resolver)
262266
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
263267
$resolver->setNormalizer('id_reader', $idReaderNormalizer);
264268

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

268272
/**
@@ -273,7 +277,7 @@ public function configureOptions(OptionsResolver $resolver)
273277
*
274278
* @return EntityLoaderInterface
275279
*/
276-
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);
280+
abstract public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class);
277281

278282
public function getParent()
279283
{

src/Symfony/Bridge/Doctrine/Form/Type/EntityType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

14-
use Doctrine\Common\Persistence\ObjectManager;
14+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
1515
use Doctrine\ORM\Query\Parameter;
1616
use Doctrine\ORM\QueryBuilder;
1717
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
@@ -51,7 +51,7 @@ public function configureOptions(OptionsResolver $resolver)
5151
*
5252
* @return ORMQueryBuilderLoader
5353
*/
10000
54-
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
54+
public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class)
5555
{
5656
return new ORMQueryBuilderLoader($queryBuilder);
5757
}

src/Symfony/Bridge/Doctrine/ManagerRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine;
1313

14-
use Doctrine\Common\Persistence\AbstractManagerRegistry;
14+
use Doctrine\Common\Persistence\AbstractManagerRegistry as LegacyAbstractManagerRegistry;
1515
use ProxyManager\Proxy\LazyLoadingInterface;
1616
use Symfony\Component\DependencyInjection\Container;
1717
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
@@ -22,7 +22,7 @@
2222
*
2323
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
2424
*/
25-
abstract class ManagerRegistry extends AbstractManagerRegistry implements ContainerAwareInterface
25+
abstract class ManagerRegistry extends LegacyAbstractManagerRegistry implements ContainerAwareInterface
2626
{
2727
/**
2828
* @var Container

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111

1212
namespace Symfony\Bridge\Doctrine\PropertyInfo;
1313

14-
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
15-
use Doctrine\Common\Persistence\Mapping\MappingException;
14+
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory as LegacyClassMetadataFactory;
15+
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyMappingException;
1616
use Doctrine\DBAL\Types\Type as DBALType;
1717
use Doctrine\ORM\Mapping\ClassMetadataInfo;
1818
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
19+
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
20+
use Doctrine\Persistence\Mapping\MappingException;
1921
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
2022
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
2123
use Symfony\Component\PropertyInfo\Type;
@@ -29,7 +31,10 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
2931
{
3032
private $classMetadataFactory;
3133

32-
public function __construct(ClassMetadataFactory $classMetadataFactory)
34+
/**
35+
* @param ClassMetadataFactory|LegacyClassMetadataFactory $classMetadataFactory
36+
*/
37+
public function __construct($classMetadataFactory)
3338
{
3439
$this->classMetadataFactory = $classMetadataFactory;
3540
}
@@ -45,6 +50,8 @@ public function getProperties($class, array $context = [])
4550
return null;
4651
} catch (OrmMappingException $exception) {
4752
return null;
53+
} catch (LegacyMappingException $exception) {
54+
return null;
4855
}
4956

5057
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
@@ -71,6 +78,8 @@ public function getTypes($class, $property, array $context = [])
7178
return null;
7279
} catch (OrmMappingException $exception) {
7380
return null;
81+
} catch (LegacyMappingException $exception) {
82+
return null;
7483
}
7584

7685
if ($metadata->hasAssociation($property)) {

src/Symfony/Bridge/Doctrine/RegistryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
namespace Symfony\Bridge\Doctrine;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry as ManagerRegistryInterface;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
1515
use Doctrine\ORM\EntityManager;
1616

1717
/**
1818
* References Doctrine connections and entity managers.
1919
*
2020
* @author Fabien Potencier <fabien@symfony.com>
2121
*/
22-
interface RegistryInterface extends ManagerRegistryInterface
22+
interface RegistryInterface extends LegacyManagerRegistry
2323
{
2424
/**
2525
* Gets the default entity manager name.

src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Security\User;
1313

14-
use Doctrine\Common\Persistence\ManagerRegistry;
14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
15+
use Doctrine\Persistence\ManagerRegistry;
1516
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1617
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1718
use Symfony\Component\Security\Core\User\UserInterface;
@@ -33,7 +34,10 @@ class EntityUserProvider implements UserProviderInterface
3334
private $class;
3435
private $property;
3536

36-
public function __construct(ManagerRegistry $registry, $classOrAlias, $property = null, $managerName = null)
37+
/**
38+
* @param ManagerRegistry|LegacyManagerRegistry $registry
39+
*/
40+
public function __construct($registry, $classOrAlias, $property = null, $managerName = null)
3741
{
3842
$this->registry = $registry;
3943
$this->managerName = $managerName;

src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Test;
1313

14-
use Doctrine\Common\Persistence\ObjectRepository;
14+
use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
1515
use Doctrine\ORM\EntityManagerInterface;
1616
use Doctrine\ORM\Mapping\ClassMetadata;
1717
use Doctrine\ORM\Repository\RepositoryFactory;
18+
use Doctrine\Persistence\ObjectRepository;
1819

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

43-
public function setRepository(EntityManagerInterface $entityManager, $entityName, ObjectRepository $repository)
44+
public function setRepository(EntityManagerInterface $entityManager, $entityName, LegacyObjectRepository $repository)
4445
{
4546
$repositoryHash = $this->getRepositoryHash($entityManager, $entityName);
4647

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

5051
/**
51-
* @return ObjectRepository
52+
* @return ObjectRepository|LegacyObjectRepository
5253
*/
5354
private function createRepository(EntityManagerInterface $entityManager, $entityName)
5455
{

src/Symfony/Bridge/Doctrine/Tests/DataCollector/DoctrineDataCollectorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
1313

14+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
1415
use Doctrine\DBAL\Platforms\MySqlPlatform;
1516
use Doctrine\DBAL\Version;
17+
use Doctrine\Persistence\ManagerRegistry;
1618
use PHPUnit\Framework\TestCase;
1719
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
1820
use Symfony\Component\HttpFoundation\Request;
@@ -180,7 +182,7 @@ private function createCollector($queries)
180182
->method('getDatabasePlatform')
181183
->willReturn(new MySqlPlatform());
182184

183-
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock();
185+
$registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
184186
$registry
185187
->expects($this->any())
186188
->method('getConnectionNames')

0 commit comments

Comments
 (0)
0