Skip to content

Commit e412497

Browse files
Merge branch '3.4' into 4.3
* 3.4: [DoctrineBridge] try to fix deprecations from doctrine/persistence [Translation] fix memoryleak in PhpFileLoader
2 parents 33ce0d9 + c94d84f commit e412497

25 files changed

+145
-77
lines changed

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
}

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();

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]);

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\Loader\ChoiceLoaderInterface;
@@ -40,12 +41,12 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
4041
* passed which optimizes the object loading for one of the Doctrine
4142
* mapper implementations.
4243
*
43-
* @param ObjectManager $manager The object manager
44-
* @param string $class The class name of the loaded objects
45-
* @param IdReader|null $idReader The reader for the object IDs
46-
* @param EntityLoaderInterface|null $objectLoader The objects loader
44+
* @param ObjectManager|LegacyObjectManager $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
4748
*/
48-
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
49+
public function __construct($manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
4950
{
5051
$classMetadata = $manager->getClassMetadata($class);
5152

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));

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
}

Form/DoctrineOrmTypeGuesser.php

Lines changed: 14 additions & 5 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\Persistence\Proxy;
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
}
@@ -182,6 +187,8 @@ protected function getMetadata($class)
182187
return $this->cache[$class] = [$em->getClassMetadata($class), $name];
183188
} catch (MappingException $e) {
184189
// not an entity or mapped super class
190+
} catch (LegacyCommonMappingException $e) {
191+
// not an entity or mapped super class
185192
} catch (LegacyMappingException $e) {
186193
// not an entity or mapped super class, using Doctrine ORM 2.2
187194
}
@@ -192,10 +199,12 @@ protected function getMetadata($class)
192199

193200
private static function getRealClass(string $class): string
194201
{
195-
if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) {
202+
$marker = interface_exists(Proxy::class) ? '\\'.Proxy::MARKER.'\\' : '\__CG__\\';
203+
204+
if (false === $pos = strrpos($class, $marker)) {
196205
return $class;
197206
}
198207

199-
return substr($class, $pos + Proxy::MARKER_LENGTH + 2);
208+
return substr($class, $pos + \strlen($marker));
200209
}
201210
}

Form/Type/DoctrineType.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
namespace Symfony\Bridge\Doctrine\Form\Type;
1313

1414
use Doctrine\Common\Collections\Collection;
15-
use Doctrine\Common\Persistence\ManagerRegistry;
16-
use Doctrine\Common\Persistence\ObjectManager;
15+
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
16+
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
17+
use Doctrine\Persistence\ManagerRegistry;
18+
use Doctrine\Persistence\ObjectManager;
1719
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1820
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
1921
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@@ -101,7 +103,10 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder)
101103
return false;
102104
}
103105

104-
public function __construct(ManagerRegistry $registry)
106+
/**
107+
* @param ManagerRegistry|LegacyManagerRegistry $registry
108+
*/
109+
public function __construct($registry)
105110
{
106111
$this->registry = $registry;
107112
}
@@ -191,9 +196,8 @@ public function configureOptions(OptionsResolver $resolver)
191196
};
192197

193198
$emNormalizer = function (Options $options, $em) {
194-
/* @var ManagerRegistry $registry */
195199
if (null !== $em) {
196-
if ($em instanceof ObjectManager) {
200+
if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
197201
return $em;
198202
}
199203

@@ -263,7 +267,7 @@ public function configureOptions(OptionsResolver $resolver)
263267
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
264268
$resolver->setNormalizer('id_reader', $idReaderNormalizer);
265269

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

269273
/**
@@ -274,7 +278,7 @@ public function configureOptions(OptionsResolver $resolver)
274278
*
275279
* @return EntityLoaderInterface
276280
*/
277-
abstract public function getLoader(ObjectManager $manager, $queryBuilder, $class);
281+
abstract public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class);
278282

279283
public function getParent()
280284
{

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
*/
54-
public function getLoader(ObjectManager $manager, $queryBuilder, $class)
54+
public function getLoader(LegacyObjectManager $manager, $queryBuilder, $class)
5555
{
5656
return new ORMQueryBuilderLoader($queryBuilder);
5757
}

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

@@ -20,7 +20,7 @@
2020
*
2121
* @author Lukas Kahwe Smith <[email protected]>
2222
*/
23-
abstract class ManagerRegistry extends AbstractManagerRegistry
23+
abstract class ManagerRegistry extends LegacyAbstractManagerRegistry
2424
{
2525
/**
2626
* @var Container

0 commit comments

Comments
 (0)