Skip to content

Commit 773430c

Browse files
Merge branch '4.4' into 5.0
* 4.4: Fix merge [DoctrineBridge] try to fix deprecations from doctrine/persistence [DI] Add support for immutable setters in CallTrait [Cache] Propagate expiry when syncing items in ChainAdapter Removed request header "Content-Type" from the preferred format guessing mechanism [Routing] fix memoryleak when loading compiled routes [Translation] fix memoryleak in PhpFileLoader fix triggering deprecation in file locator bug #34877 [TwigBundle] fix findTemplate() to return `null`
2 parents 737af44 + 2e3828f commit 773430c

24 files changed

+153
-100
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;
@@ -37,7 +38,10 @@ class DoctrineDataCollector extends DataCollector
3738
*/
3839
private $loggers = [];
3940

40-
public function __construct(ManagerRegistry $registry)
41+
/**
42+
* @param ManagerRegistry|LegacyManagerRegistry $registry
43+
*/
44+
public function __construct($registry)
4145
{
4246
$this->registry = $registry;
4347
$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: 5 additions & 3 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,9 +41,10 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
4041
* passed which optimizes the object loading for one of the Doctrine
4142
* mapper implementations.
4243
*
43-
* @param string $class The class name of the loaded objects
44+
* @param ObjectManager|LegacyObjectManager $manager The object manager
45+
* @param string $class The class name of the loaded objects
4446
*/
45-
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
47+
public function __construct($manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
4648
{
4749
$classMetadata = $manager->getClassMetadata($class);
4850

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(string $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(string $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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +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;
17-
use Doctrine\ORM\QueryBuilder;
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;
1819
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
1920
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
2021
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@@ -96,7 +97,10 @@ public function getQueryBuilderPartsForCachingHash($queryBuilder): ?array
9697
return null;
9798
}
9899

99-
public function __construct(ManagerRegistry $registry)
100+
/**
101+
* @param ManagerRegistry|LegacyManagerRegistry $registry
102+
*/
103+
public function __construct($registry)
100104
{
101105
$this->registry = $registry;
102106
}
@@ -185,9 +189,8 @@ public function configureOptions(OptionsResolver $resolver)
185189
};
186190

187191
$emNormalizer = function (Options $options, $em) {
188-
/* @var ManagerRegistry $registry */
189192
if (null !== $em) {
190-
if ($em instanceof ObjectManager) {
193+
if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
191194
return $em;
192195
}
193196

@@ -257,7 +260,7 @@ public function configureOptions(OptionsResolver $resolver)
257260
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
258261
$resolver->setNormalizer('id_reader', $idReaderNormalizer);
259262

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

263266
/**
@@ -267,7 +270,7 @@ public function configureOptions(OptionsResolver $resolver)
267270
*
268271
* @return EntityLoaderInterface
269272
*/
270-
abstract public function getLoader(ObjectManager $manager, $queryBuilder, string $class);
273+
abstract public function getLoader(LegacyObjectManager $manager, $queryBuilder, string $class);
271274

272275
public function getParent()
273276
{

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;
@@ -50,7 +50,7 @@ public function configureOptions(OptionsResolver $resolver)
5050
*
5151
* @return ORMQueryBuilderLoader
5252
*/
53-
public function getLoader(ObjectManager $manager, $queryBuilder, string $class)
53+
public function getLoader(LegacyObjectManager $manager, $queryBuilder, string $class)
5454
{
5555
if (!$queryBuilder instanceof QueryBuilder) {
5656
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));

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)