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`
This commit is contained in:
Nicolas Grekas 2019-12-12 14:03:32 +01:00
commit cf073e563f
34 changed files with 220 additions and 131 deletions

View File

@ -11,7 +11,8 @@
namespace Symfony\Bridge\Doctrine\CacheWarmer; 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; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
/** /**
@ -26,7 +27,10 @@ class ProxyCacheWarmer implements CacheWarmerInterface
{ {
private $registry; private $registry;
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }

View File

@ -11,10 +11,11 @@
namespace Symfony\Bridge\Doctrine\DataCollector; 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\Logging\DebugStack;
use Doctrine\DBAL\Types\ConversionException; use Doctrine\DBAL\Types\ConversionException;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector; use Symfony\Component\HttpKernel\DataCollector\DataCollector;
@ -37,7 +38,10 @@ class DoctrineDataCollector extends DataCollector
*/ */
private $loggers = []; private $loggers = [];
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
$this->connections = $registry->getConnectionNames(); $this->connections = $registry->getConnectionNames();

View File

@ -143,7 +143,7 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
$mappingDriverDef = $this->getDriver($container); $mappingDriverDef = $this->getDriver($container);
$chainDriverDefService = $this->getChainDriverServiceName($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); $chainDriverDef = $container->getDefinition($chainDriverDefService);
foreach ($this->namespaces as $namespace) { foreach ($this->namespaces as $namespace) {
$chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]); $chainDriverDef->addMethodCall('addDriver', [$mappingDriverDef, $namespace]);

View File

@ -11,7 +11,8 @@
namespace Symfony\Bridge\Doctrine\Form\ChoiceList; 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\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
@ -40,9 +41,10 @@ class DoctrineChoiceLoader implements ChoiceLoaderInterface
* passed which optimizes the object loading for one of the Doctrine * passed which optimizes the object loading for one of the Doctrine
* mapper implementations. * mapper implementations.
* *
* @param string $class The class name of the loaded objects * @param ObjectManager|LegacyObjectManager $manager The object manager
* @param string $class The class name of the loaded objects
*/ */
public function __construct(ObjectManager $manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null) public function __construct($manager, string $class, IdReader $idReader = null, EntityLoaderInterface $objectLoader = null)
{ {
$classMetadata = $manager->getClassMetadata($class); $classMetadata = $manager->getClassMetadata($class);

View File

@ -11,8 +11,10 @@
namespace Symfony\Bridge\Doctrine\Form\ChoiceList; namespace Symfony\Bridge\Doctrine\Form\ChoiceList;
use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\Exception\RuntimeException; use Symfony\Component\Form\Exception\RuntimeException;
/** /**
@ -35,7 +37,11 @@ class IdReader
*/ */
private $associationIdReader; 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(); $ids = $classMetadata->getIdentifierFieldNames();
$idType = $classMetadata->getTypeOfField(current($ids)); $idType = $classMetadata->getTypeOfField(current($ids));

View File

@ -11,7 +11,8 @@
namespace Symfony\Bridge\Doctrine\Form; 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\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractExtension; use Symfony\Component\Form\AbstractExtension;
@ -19,7 +20,10 @@ class DoctrineOrmExtension extends AbstractExtension
{ {
protected $registry; protected $registry;
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }

View File

@ -11,12 +11,14 @@
namespace Symfony\Bridge\Doctrine\Form; namespace Symfony\Bridge\Doctrine\Form;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\Persistence\Mapping\MappingException as LegacyCommonMappingException;
use Doctrine\Common\Persistence\Proxy; use Doctrine\Common\Persistence\Proxy;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException; 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\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\TypeGuess; use Symfony\Component\Form\Guess\TypeGuess;
@ -28,7 +30,10 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
private $cache = []; private $cache = [];
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }
@ -182,6 +187,8 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
return $this->cache[$class] = [$em->getClassMetadata($class), $name]; return $this->cache[$class] = [$em->getClassMetadata($class), $name];
} catch (MappingException $e) { } catch (MappingException $e) {
// not an entity or mapped super class // not an entity or mapped super class
} catch (LegacyCommonMappingException $e) {
// not an entity or mapped super class
} catch (LegacyMappingException $e) { } catch (LegacyMappingException $e) {
// not an entity or mapped super class, using Doctrine ORM 2.2 // not an entity or mapped super class, using Doctrine ORM 2.2
} }
@ -192,10 +199,12 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
private static function getRealClass(string $class): string private static function getRealClass(string $class): string
{ {
if (false === $pos = strrpos($class, '\\'.Proxy::MARKER.'\\')) { $marker = interface_exists(Proxy::class) ? '\\'.Proxy::MARKER.'\\' : '\__CG__\\';
if (false === $pos = strrpos($class, $marker)) {
return $class; return $class;
} }
return substr($class, $pos + Proxy::MARKER_LENGTH + 2); return substr($class, $pos + \strlen($marker));
} }
} }

View File

@ -12,9 +12,10 @@
namespace Symfony\Bridge\Doctrine\Form\Type; namespace Symfony\Bridge\Doctrine\Form\Type;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\ORM\QueryBuilder; use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader; use Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader;
@ -96,7 +97,10 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
return null; return null;
} }
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }
@ -185,9 +189,8 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
}; };
$emNormalizer = function (Options $options, $em) { $emNormalizer = function (Options $options, $em) {
/* @var ManagerRegistry $registry */
if (null !== $em) { if (null !== $em) {
if ($em instanceof ObjectManager) { if ($em instanceof ObjectManager || $em instanceof LegacyObjectManager) {
return $em; return $em;
} }
@ -257,7 +260,7 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
$resolver->setNormalizer('query_builder', $queryBuilderNormalizer); $resolver->setNormalizer('query_builder', $queryBuilderNormalizer);
$resolver->setNormalizer('id_reader', $idReaderNormalizer); $resolver->setNormalizer('id_reader', $idReaderNormalizer);
$resolver->setAllowedTypes('em', ['null', 'string', 'Doctrine\Common\Persistence\ObjectManager']); $resolver->setAllowedTypes('em', ['null', 'string', ObjectManager::class, LegacyObjectManager::class]);
} }
/** /**
@ -267,7 +270,7 @@ abstract class DoctrineType extends AbstractType implements ResetInterface
* *
* @return EntityLoaderInterface * @return EntityLoaderInterface
*/ */
abstract public function getLoader(ObjectManager $manager, $queryBuilder, string $class); abstract public function getLoader(LegacyObjectManager $manager, $queryBuilder, string $class);
public function getParent() public function getParent()
{ {

View File

@ -11,7 +11,7 @@
namespace Symfony\Bridge\Doctrine\Form\Type; 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\Query\Parameter;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader; use Symfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
@ -50,7 +50,7 @@ class EntityType extends DoctrineType
* *
* @return ORMQueryBuilderLoader * @return ORMQueryBuilderLoader
*/ */
public function getLoader(ObjectManager $manager, $queryBuilder, string $class) public function getLoader(LegacyObjectManager $manager, $queryBuilder, string $class)
{ {
if (!$queryBuilder instanceof QueryBuilder) { if (!$queryBuilder instanceof QueryBuilder) {
throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder))); throw new \TypeError(sprintf('Expected an instance of %s, but got %s.', QueryBuilder::class, \is_object($queryBuilder) ? \get_class($queryBuilder) : \gettype($queryBuilder)));

View File

@ -11,7 +11,7 @@
namespace Symfony\Bridge\Doctrine; namespace Symfony\Bridge\Doctrine;
use Doctrine\Common\Persistence\AbstractManagerRegistry; use Doctrine\Common\Persistence\AbstractManagerRegistry as LegacyAbstractManagerRegistry;
use ProxyManager\Proxy\LazyLoadingInterface; use ProxyManager\Proxy\LazyLoadingInterface;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
@ -20,7 +20,7 @@ use Symfony\Component\DependencyInjection\Container;
* *
* @author Lukas Kahwe Smith <smith@pooteeweet.org> * @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/ */
abstract class ManagerRegistry extends AbstractManagerRegistry abstract class ManagerRegistry extends LegacyAbstractManagerRegistry
{ {
/** /**
* @var Container * @var Container

View File

@ -11,12 +11,13 @@
namespace Symfony\Bridge\Doctrine\PropertyInfo; namespace Symfony\Bridge\Doctrine\PropertyInfo;
use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Common\Persistence\Mapping\MappingException as LegacyMappingException;
use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as OrmMappingException; use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
use Doctrine\Persistence\Mapping\MappingException;
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface; use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface; use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface; use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
@ -189,7 +190,7 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
{ {
try { try {
return $this->entityManager ? $this->entityManager->getClassMetadata($class) : $this->classMetadataFactory->getMetadataFor($class); return $this->entityManager ? $this->entityManager->getClassMetadata($class) : $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException | OrmMappingException $exception) { } catch (MappingException | OrmMappingException | LegacyMappingException $exception) {
return null; return null;
} }
} }

View File

@ -11,10 +11,8 @@
namespace Symfony\Bridge\Doctrine\Security\User; namespace Symfony\Bridge\Doctrine\Security\User;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
@ -37,7 +35,10 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
private $class; private $class;
private $property; private $property;
public function __construct(ManagerRegistry $registry, string $classOrAlias, string $property = null, string $managerName = null) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry, string $classOrAlias, string $property = null, string $managerName = null)
{ {
$this->registry = $registry; $this->registry = $registry;
$this->managerName = $managerName; $this->managerName = $managerName;
@ -50,7 +51,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
*/ */
public function loadUserByUsername(string $username) public function loadUserByUsername(string $username)
{ {
$repository = $this->getRepository(); $repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
if (null !== $this->property) { if (null !== $this->property) {
$user = $repository->findOneBy([$this->property => $username]); $user = $repository->findOneBy([$this->property => $username]);
} else { } else {
@ -78,7 +79,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
} }
$repository = $this->getRepository(); $repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
if ($repository instanceof UserProviderInterface) { if ($repository instanceof UserProviderInterface) {
$refreshedUser = $repository->refreshUser($user); $refreshedUser = $repository->refreshUser($user);
} else { } else {
@ -86,7 +87,7 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
// might have changed without proper persistence in the database. // might have changed without proper persistence in the database.
// That's the case when the user has been changed by a form with // That's the case when the user has been changed by a form with
// validation errors. // validation errors.
if (!$id = $this->getClassMetadata()->getIdentifierValues($user)) { if (!$id = $this->registry->getManager($this->managerName)->getClassMetadata($this->classOrAlias)->getIdentifierValues($user)) {
throw new \InvalidArgumentException('You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.'); throw new \InvalidArgumentException('You cannot refresh a user from the EntityUserProvider that does not contain an identifier. The user object has to be serialized with its own identifier mapped by Doctrine.');
} }
@ -117,29 +118,19 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
} }
$repository = $this->getRepository(); $repository = $this->registry->getManager($this->managerName)->getRepository($this->classOrAlias);
if ($repository instanceof PasswordUpgraderInterface) { if ($repository instanceof PasswordUpgraderInterface) {
$repository->upgradePassword($user, $newEncodedPassword); $repository->upgradePassword($user, $newEncodedPassword);
} }
} }
private function getObjectManager(): ObjectManager
{
return $this->registry->getManager($this->managerName);
}
private function getRepository(): ObjectRepository
{
return $this->getObjectManager()->getRepository($this->classOrAlias);
}
private function getClass(): string private function getClass(): string
{ {
if (null === $this->class) { if (null === $this->class) {
$class = $this->classOrAlias; $class = $this->classOrAlias;
if (false !== strpos($class, ':')) { if (false !== strpos($class, ':')) {
$class = $this->getClassMetadata()->getName(); $class = $this->registry->getManager($this->managerName)->getClassMetadata($this->classOrAlias)->getName();
} }
$this->class = $class; $this->class = $class;
@ -147,9 +138,4 @@ class EntityUserProvider implements UserProviderInterface, PasswordUpgraderInter
return $this->class; return $this->class;
} }
private function getClassMetadata(): ClassMetadata
{
return $this->getObjectManager()->getClassMetadata($this->classOrAlias);
}
} }

View File

@ -13,12 +13,14 @@ namespace Symfony\Bridge\Doctrine\Test;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain as LegacyMappingDriverChain;
use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator as LegacySymfonyFileLocator;
use Doctrine\ORM\Configuration; use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver; use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
/** /**
@ -74,11 +76,13 @@ class DoctrineTestHelper
public static function createTestConfigurationWithXmlLoader() public static function createTestConfigurationWithXmlLoader()
{ {
$config = static::createTestConfiguration(); $config = static::createTestConfiguration();
$symfonyFileLocator = class_exists(SymfonyFileLocator::class) ? SymfonyFileLocator::class : LegacySymfonyFileLocator::class;
$driverChain = class_exists(MappingDriverChain::class) ? MappingDriverChain::class : LegacyMappingDriverChain::class;
$driverChain = new MappingDriverChain(); $driverChain = new MappingDriverChain();
$driverChain->addDriver( $driverChain->addDriver(
new XmlDriver( new XmlDriver(
new SymfonyFileLocator( new $symfonyFileLocator(
[__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml' [__DIR__.'/../Tests/Resources/orm' => 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures'], '.orm.xml'
) )
), ),

View File

@ -11,10 +11,11 @@
namespace Symfony\Bridge\Doctrine\Test; namespace Symfony\Bridge\Doctrine\Test;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Repository\RepositoryFactory; use Doctrine\ORM\Repository\RepositoryFactory;
use Doctrine\Persistence\ObjectRepository;
/** /**
* @author Andreas Braun <alcaeus@alcaeus.org> * @author Andreas Braun <alcaeus@alcaeus.org>
@ -40,14 +41,17 @@ final class TestRepositoryFactory implements RepositoryFactory
return $this->repositoryList[$repositoryHash] = $this->createRepository($entityManager, $entityName); return $this->repositoryList[$repositoryHash] = $this->createRepository($entityManager, $entityName);
} }
public function setRepository(EntityManagerInterface $entityManager, string $entityName, ObjectRepository $repository) public function setRepository(EntityManagerInterface $entityManager, string $entityName, LegacyObjectRepository $repository)
{ {
$repositoryHash = $this->getRepositoryHash($entityManager, $entityName); $repositoryHash = $this->getRepositoryHash($entityManager, $entityName);
$this->repositoryList[$repositoryHash] = $repository; $this->repositoryList[$repositoryHash] = $repository;
} }
private function createRepository(EntityManagerInterface $entityManager, string $entityName): ObjectRepository /**
* @return ObjectRepository|LegacyObjectRepository
*/
private function createRepository(EntityManagerInterface $entityManager, string $entityName)
{ {
/* @var $metadata ClassMetadata */ /* @var $metadata ClassMetadata */
$metadata = $entityManager->getClassMetadata($entityName); $metadata = $entityManager->getClassMetadata($entityName);

View File

@ -11,8 +11,10 @@
namespace Symfony\Bridge\Doctrine\Tests\DataCollector; namespace Symfony\Bridge\Doctrine\Tests\DataCollector;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Version; use Doctrine\DBAL\Version;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector; use Symfony\Bridge\Doctrine\DataCollector\DoctrineDataCollector;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@ -235,7 +237,7 @@ EOTXT
->method('getDatabasePlatform') ->method('getDatabasePlatform')
->willReturn(new MySqlPlatform()); ->willReturn(new MySqlPlatform());
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$registry $registry
->expects($this->any()) ->expects($this->any())
->method('getConnectionNames') ->method('getConnectionNames')

View File

@ -12,7 +12,7 @@
namespace Symfony\Bridge\Doctrine\Tests\Fixtures; namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
@ -25,7 +25,7 @@ class ContainerAwareFixture implements FixtureInterface, ContainerAwareInterface
$this->container = $container; $this->container = $container;
} }
public function load(ObjectManager $manager) public function load(LegacyObjectManager $manager)
{ {
} }
} }

View File

@ -11,9 +11,11 @@
namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList; namespace Symfony\Bridge\Doctrine\Tests\Form\ChoiceList;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader; use Symfony\Bridge\Doctrine\Form\ChoiceList\DoctrineChoiceLoader;
@ -75,8 +77,8 @@ class DoctrineChoiceLoaderTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->factory = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface')->getMock(); $this->factory = $this->getMockBuilder('Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface')->getMock();
$this->om = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock(); $this->om = $this->getMockBuilder(interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class)->getMock();
$this->repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository')->getMock(); $this->repository = $this->getMockBuilder(interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class)->getMock();
$this->class = 'stdClass'; $this->class = 'stdClass';
$this->idReader = $this->getMockBuilder('Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader') $this->idReader = $this->getMockBuilder('Symfony\Bridge\Doctrine\Form\ChoiceList\IdReader')
->disableOriginalConstructor() ->disableOriginalConstructor()

View File

@ -11,7 +11,11 @@
namespace Symfony\Bridge\Doctrine\Tests\Form; namespace Symfony\Bridge\Doctrine\Tests\Form;
use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\Guess;
@ -83,10 +87,10 @@ class DoctrineOrmTypeGuesserTest extends TestCase
private function getGuesser(ClassMetadata $classMetadata) private function getGuesser(ClassMetadata $classMetadata)
{ {
$em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager')->getMock(); $em = $this->getMockBuilder(interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class)->getMock();
$em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata); $em->expects($this->once())->method('getClassMetaData')->with('TestEntity')->willReturn($classMetadata);
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$registry->expects($this->once())->method('getManagers')->willReturn([$em]); $registry->expects($this->once())->method('getManagers')->willReturn([$em]);
return new DoctrineOrmTypeGuesser($registry); return new DoctrineOrmTypeGuesser($registry);

View File

@ -11,7 +11,9 @@
namespace Symfony\Bridge\Doctrine\Tests\Form\Type; namespace Symfony\Bridge\Doctrine\Tests\Form\Type;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
@ -34,7 +36,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase
protected function getExtensions() protected function getExtensions()
{ {
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $manager = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$manager->expects($this->any()) $manager->expects($this->any())
->method('getManager') ->method('getManager')

View File

@ -12,10 +12,11 @@
namespace Symfony\Bridge\Doctrine\Tests\Form\Type; namespace Symfony\Bridge\Doctrine\Tests\Form\Type;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension; use Symfony\Bridge\Doctrine\Form\DoctrineOrmExtension;
use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser; use Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser;
@ -1226,7 +1227,7 @@ class EntityTypeTest extends BaseTypeTest
protected function createRegistryMock($name, $em) protected function createRegistryMock($name, $em)
{ {
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$registry->expects($this->any()) $registry->expects($this->any())
->method('getManager') ->method('getManager')
->with($this->equalTo($name)) ->with($this->equalTo($name))

View File

@ -11,8 +11,13 @@
namespace Symfony\Bridge\Doctrine\Tests\Security\User; namespace Symfony\Bridge\Doctrine\Tests\Security\User;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider; use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface; use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
@ -61,7 +66,7 @@ class EntityUserProviderTest extends TestCase
{ {
$user = new User(1, 1, 'user1'); $user = new User(1, 1, 'user1');
$repository = $this->createMock([ObjectRepository::class, UserLoaderInterface::class]); $repository = $this->createMock([interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class, UserLoaderInterface::class]);
$repository $repository
->expects($this->once()) ->expects($this->once())
->method('loadUserByUsername') ->method('loadUserByUsername')
@ -147,7 +152,7 @@ class EntityUserProviderTest extends TestCase
public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided() public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()
{ {
$repository = $this->createMock([ObjectRepository::class, UserLoaderInterface::class]); $repository = $this->createMock([interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class, UserLoaderInterface::class]);
$repository->expects($this->once()) $repository->expects($this->once())
->method('loadUserByUsername') ->method('loadUserByUsername')
->with('name') ->with('name')
@ -166,7 +171,7 @@ class EntityUserProviderTest extends TestCase
public function testLoadUserByUserNameShouldDeclineInvalidInterface() public function testLoadUserByUserNameShouldDeclineInvalidInterface()
{ {
$this->expectException('InvalidArgumentException'); $this->expectException('InvalidArgumentException');
$repository = $this->createMock(ObjectRepository::class); $repository = $this->createMock(interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class);
$provider = new EntityUserProvider( $provider = new EntityUserProvider(
$this->getManager($this->getObjectManager($repository)), $this->getManager($this->getObjectManager($repository)),
@ -180,7 +185,7 @@ class EntityUserProviderTest extends TestCase
{ {
$user = new User(1, 1, 'user1'); $user = new User(1, 1, 'user1');
$repository = $this->createMock([ObjectRepository::class, PasswordUpgraderInterface::class]); $repository = $this->createMock([interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class, PasswordUpgraderInterface::class]);
$repository->expects($this->once()) $repository->expects($this->once())
->method('upgradePassword') ->method('upgradePassword')
->with($user, 'foobar'); ->with($user, 'foobar');
@ -195,7 +200,7 @@ class EntityUserProviderTest extends TestCase
private function getManager($em, $name = null) private function getManager($em, $name = null)
{ {
$manager = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $manager = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$manager->expects($this->any()) $manager->expects($this->any())
->method('getManager') ->method('getManager')
->with($this->equalTo($name)) ->with($this->equalTo($name))
@ -206,7 +211,7 @@ class EntityUserProviderTest extends TestCase
private function getObjectManager($repository) private function getObjectManager($repository)
{ {
$em = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager') $em = $this->getMockBuilder(interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class)
->setMethods(['getClassMetadata', 'getRepository']) ->setMethods(['getClassMetadata', 'getRepository'])
->getMockForAbstractClass(); ->getMockForAbstractClass();
$em->expects($this->any()) $em->expects($this->any())

View File

@ -12,11 +12,16 @@
namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints; namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\Persistence\Mapping\ClassMetadata as LegacyClassMetadata;
use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager;
use Doctrine\Common\Persistence\ObjectRepository as LegacyObjectRepository;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Tools\SchemaTool; use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper; use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Test\TestRepositoryFactory; use Symfony\Bridge\Doctrine\Test\TestRepositoryFactory;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity; use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
@ -76,9 +81,9 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
parent::setUp(); parent::setUp();
} }
protected function createRegistryMock(ObjectManager $em = null) protected function createRegistryMock($em = null)
{ {
$registry = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $registry = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$registry->expects($this->any()) $registry->expects($this->any())
->method('getManager') ->method('getManager')
->with($this->equalTo(self::EM_NAME)) ->with($this->equalTo(self::EM_NAME))
@ -89,7 +94,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
protected function createRepositoryMock() protected function createRepositoryMock()
{ {
$repository = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectRepository') $repository = $this->getMockBuilder(interface_exists(ObjectRepository::class) ? ObjectRepository::class : LegacyObjectRepository::class)
->setMethods(['findByCustom', 'find', 'findAll', 'findOneBy', 'findBy', 'getClassName']) ->setMethods(['findByCustom', 'find', 'findAll', 'findOneBy', 'findBy', 'getClassName'])
->getMock() ->getMock()
; ;
@ -99,7 +104,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
protected function createEntityManagerMock($repositoryMock) protected function createEntityManagerMock($repositoryMock)
{ {
$em = $this->getMockBuilder('Doctrine\Common\Persistence\ObjectManager') $em = $this->getMockBuilder(interface_exists(ObjectManager::class) ? ObjectManager::class : LegacyObjectManager::class)
->getMock() ->getMock()
; ;
$em->expects($this->any()) $em->expects($this->any())
@ -107,7 +112,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
->willReturn($repositoryMock) ->willReturn($repositoryMock)
; ;
$classMetadata = $this->getMockBuilder('Doctrine\Common\Persistence\Mapping\ClassMetadata')->getMock(); $classMetadata = $this->getMockBuilder(interface_exists(ClassMetadata::class) ? ClassMetadata::class : LegacyClassMetadata::class)->getMock();
$classMetadata $classMetadata
->expects($this->any()) ->expects($this->any())
->method('hasField') ->method('hasField')
@ -141,7 +146,7 @@ class UniqueEntityValidatorTest extends ConstraintValidatorTestCase
return new UniqueEntityValidator($this->registry); return new UniqueEntityValidator($this->registry);
} }
private function createSchema(ObjectManager $em) private function createSchema($em)
{ {
$schemaTool = new SchemaTool($em); $schemaTool = new SchemaTool($em);
$schemaTool->createSchema([ $schemaTool->createSchema([

View File

@ -11,9 +11,8 @@
namespace Symfony\Bridge\Doctrine\Validator\Constraints; namespace Symfony\Bridge\Doctrine\Validator\Constraints;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException; use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@ -28,7 +27,10 @@ class UniqueEntityValidator extends ConstraintValidator
{ {
private $registry; private $registry;
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }
@ -78,7 +80,6 @@ class UniqueEntityValidator extends ConstraintValidator
} }
$class = $em->getClassMetadata(\get_class($entity)); $class = $em->getClassMetadata(\get_class($entity));
/* @var $class \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$criteria = []; $criteria = [];
$hasNullValue = false; $hasNullValue = false;
@ -179,7 +180,7 @@ class UniqueEntityValidator extends ConstraintValidator
->addViolation(); ->addViolation();
} }
private function formatWithIdentifiers(ObjectManager $em, ClassMetadata $class, $value) private function formatWithIdentifiers($em, $class, $value)
{ {
if (!\is_object($value) || $value instanceof \DateTimeInterface) { if (!\is_object($value) || $value instanceof \DateTimeInterface) {
return $this->formatValue($value, self::PRETTY_DATE); return $this->formatValue($value, self::PRETTY_DATE);

View File

@ -11,7 +11,8 @@
namespace Symfony\Bridge\Doctrine\Validator; namespace Symfony\Bridge\Doctrine\Validator;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\ObjectInitializerInterface;
/** /**
@ -23,7 +24,10 @@ class DoctrineInitializer implements ObjectInitializerInterface
{ {
protected $registry; protected $registry;
public function __construct(ManagerRegistry $registry) /**
* @param ManagerRegistry|LegacyManagerRegistry $registry
*/
public function __construct($registry)
{ {
$this->registry = $registry; $this->registry = $registry;
} }

View File

@ -11,7 +11,8 @@
namespace Symfony\Bundle\FrameworkBundle\Controller; namespace Symfony\Bundle\FrameworkBundle\Controller;
use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Link\LinkInterface; use Psr\Link\LinkInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
@ -94,7 +95,7 @@ abstract class AbstractController implements ServiceSubscriberInterface
'session' => '?'.SessionInterface::class, 'session' => '?'.SessionInterface::class,
'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class, 'security.authorization_checker' => '?'.AuthorizationCheckerInterface::class,
'twig' => '?'.Environment::class, 'twig' => '?'.Environment::class,
'doctrine' => '?'.ManagerRegistry::class, 'doctrine' => '?'.(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class),
'form.factory' => '?'.FormFactoryInterface::class, 'form.factory' => '?'.FormFactoryInterface::class,
'security.token_storage' => '?'.TokenStorageInterface::class, 'security.token_storage' => '?'.TokenStorageInterface::class,
'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class, 'security.csrf.token_manager' => '?'.CsrfTokenManagerInterface::class,
@ -337,9 +338,11 @@ abstract class AbstractController implements ServiceSubscriberInterface
/** /**
* Shortcut to return the Doctrine Registry service. * Shortcut to return the Doctrine Registry service.
* *
* @return ManagerRegistry|LegacyManagerRegistry
*
* @throws \LogicException If DoctrineBundle is not available * @throws \LogicException If DoctrineBundle is not available
*/ */
protected function getDoctrine(): ManagerRegistry protected function getDoctrine()
{ {
if (!$this->container->has('doctrine')) { if (!$this->container->has('doctrine')) {
throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".'); throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');

View File

@ -11,6 +11,8 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Controller; namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase; use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
@ -53,7 +55,7 @@ class AbstractControllerTest extends TestCase
'session' => '?Symfony\\Component\\HttpFoundation\\Session\\SessionInterface', 'session' => '?Symfony\\Component\\HttpFoundation\\Session\\SessionInterface',
'security.authorization_checker' => '?Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface', 'security.authorization_checker' => '?Symfony\\Component\\Security\\Core\\Authorization\\AuthorizationCheckerInterface',
'twig' => '?Twig\\Environment', 'twig' => '?Twig\\Environment',
'doctrine' => '?Doctrine\\Common\\Persistence\\ManagerRegistry', 'doctrine' => '?'.(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class),
'form.factory' => '?Symfony\\Component\\Form\\FormFactoryInterface', 'form.factory' => '?Symfony\\Component\\Form\\FormFactoryInterface',
'parameter_bag' => '?Symfony\\Component\\DependencyInjection\\ParameterBag\\ContainerBagInterface', 'parameter_bag' => '?Symfony\\Component\\DependencyInjection\\ParameterBag\\ContainerBagInterface',
'message_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface', 'message_bus' => '?Symfony\\Component\\Messenger\\MessageBusInterface',
@ -532,7 +534,7 @@ class AbstractControllerTest extends TestCase
public function testGetDoctrine() public function testGetDoctrine()
{ {
$doctrine = $this->getMockBuilder('Doctrine\Common\Persistence\ManagerRegistry')->getMock(); $doctrine = $this->getMockBuilder(interface_exists(ManagerRegistry::class) ? ManagerRegistry::class : LegacyManagerRegistry::class)->getMock();
$container = new Container(); $container = new Container();
$container->set('doctrine', $doctrine); $container->set('doctrine', $doctrine);

View File

@ -61,14 +61,15 @@ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
$this->adapterCount = \count($this->adapters); $this->adapterCount = \count($this->adapters);
$this->syncItem = \Closure::bind( $this->syncItem = \Closure::bind(
static function ($sourceItem, $item) use ($defaultLifetime) { static function ($sourceItem, $item, $sourceMetadata = null) use ($defaultLifetime) {
$item->value = $sourceItem->value;
$item->expiry = $sourceItem->expiry;
$item->isHit = $sourceItem->isHit;
$item->metadata = $sourceItem->metadata;
$sourceItem->isTaggable = false; $sourceItem->isTaggable = false;
unset($sourceItem->metadata[CacheItem::METADATA_TAGS]); $sourceMetadata = $sourceMetadata ?? $sourceItem->metadata;
unset($sourceMetadata[CacheItem::METADATA_TAGS]);
$item->value = $sourceItem->value;
$item->expiry = $sourceMetadata[CacheItem::METADATA_EXPIRY] ?? $sourceItem->expiry;
$item->isHit = $sourceItem->isHit;
$item->metadata = $item->newMetadata = $sourceItem->metadata = $sourceMetadata;
if (0 < $sourceItem->defaultLifetime && $sourceItem->defaultLifetime < $defaultLifetime) { if (0 < $sourceItem->defaultLifetime && $sourceItem->defaultLifetime < $defaultLifetime) {
$defaultLifetime = $sourceItem->defaultLifetime; $defaultLifetime = $sourceItem->defaultLifetime;
@ -103,7 +104,7 @@ class ChainAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
$value = $this->doGet($adapter, $key, $callback, $beta, $metadata); $value = $this->doGet($adapter, $key, $callback, $beta, $metadata);
} }
if (null !== $item) { if (null !== $item) {
($this->syncItem)($lastItem = $lastItem ?? $item, $item); ($this->syncItem)($lastItem = $lastItem ?? $item, $item, $metadata);
} }
return $value; return $value;

View File

@ -28,7 +28,7 @@ class ChainAdapterTest extends AdapterTestCase
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
{ {
if ('testGetMetadata' === $testMethod) { if ('testGetMetadata' === $testMethod) {
return new ChainAdapter([new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime); return new ChainAdapter([new FilesystemAdapter('a', $defaultLifetime), new FilesystemAdapter('b', $defaultLifetime)], $defaultLifetime);
} }
return new ChainAdapter([new ArrayAdapter($defaultLifetime), new ExternalAdapter(), new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime); return new ChainAdapter([new ArrayAdapter($defaultLifetime), new ExternalAdapter(), new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime);

View File

@ -18,16 +18,17 @@ trait CallTrait
/** /**
* Adds a method to call after service initialization. * Adds a method to call after service initialization.
* *
* @param string $method The method name to call * @param string $method The method name to call
* @param array $arguments An array of arguments to pass to the method call * @param array $arguments An array of arguments to pass to the method call
* @param bool $returnsClone Whether the call returns the service instance or not
* *
* @return $this * @return $this
* *
* @throws InvalidArgumentException on empty $method param * @throws InvalidArgumentException on empty $method param
*/ */
final public function call(string $method, array $arguments = []): self final public function call(string $method, array $arguments = [], bool $returnsClone = false): self
{ {
$this->definition->addMethodCall($method, static::processValue($arguments, true)); $this->definition->addMethodCall($method, static::processValue($arguments, true), $returnsClone);
return $this; return $this;
} }

View File

@ -1557,20 +1557,17 @@ class Request
*/ */
public function getPreferredFormat(?string $default = 'html'): ?string public function getPreferredFormat(?string $default = 'html'): ?string
{ {
if (null !== $this->preferredFormat) { if (null !== $this->preferredFormat || null !== $this->preferredFormat = $this->getRequestFormat(null)) {
return $this->preferredFormat; return $this->preferredFormat;
} }
$preferredFormat = null; foreach ($this->getAcceptableContentTypes() as $mimeType) {
foreach ($this->getAcceptableContentTypes() as $contentType) { if ($this->preferredFormat = $this->getFormat($mimeType)) {
if ($preferredFormat = $this->getFormat($contentType)) { return $this->preferredFormat;
break;
} }
} }
$this->preferredFormat = $this->getRequestFormat($preferredFormat ?: $this->getContentType()); return $default;
return $this->preferredFormat ?: $default;
} }
/** /**

View File

@ -408,12 +408,10 @@ class RequestTest extends TestCase
$request->setRequestFormat('atom'); $request->setRequestFormat('atom');
$request->headers->set('Accept', 'application/ld+json'); $request->headers->set('Accept', 'application/ld+json');
$request->headers->set('Content-Type', 'application/merge-patch+json');
$this->assertSame('atom', $request->getPreferredFormat()); $this->assertSame('atom', $request->getPreferredFormat());
$request = new Request(); $request = new Request();
$request->headers->set('Accept', 'application/xml'); $request->headers->set('Accept', 'application/xml');
$request->headers->set('Content-Type', 'application/json');
$this->assertSame('xml', $request->getPreferredFormat()); $this->assertSame('xml', $request->getPreferredFormat());
$request = new Request(); $request = new Request();

View File

@ -92,6 +92,8 @@ class Router implements RouterInterface, RequestMatcherInterface
*/ */
private $expressionLanguageProviders = []; private $expressionLanguageProviders = [];
private static $cache = [];
/** /**
* @param mixed $resource The main resource to load * @param mixed $resource The main resource to load
*/ */
@ -295,7 +297,7 @@ class Router implements RouterInterface, RequestMatcherInterface
} }
); );
return $this->matcher = new $this->options['matcher_class'](require $cache->getPath(), $this->context); return $this->matcher = new $this->options['matcher_class'](self::getCompiledRoutes($cache->getPath()), $this->context);
} }
/** /**
@ -325,7 +327,7 @@ class Router implements RouterInterface, RequestMatcherInterface
} }
); );
$this->generator = new $this->options['generator_class'](require $cache->getPath(), $this->context, $this->logger, $this->defaultLocale); $this->generator = new $this->options['generator_class'](self::getCompiledRoutes($cache->getPath()), $this->context, $this->logger, $this->defaultLocale);
} }
if ($this->generator instanceof ConfigurableRequirementsInterface) { if ($this->generator instanceof ConfigurableRequirementsInterface) {
@ -368,4 +370,21 @@ class Router implements RouterInterface, RequestMatcherInterface
return $this->configCacheFactory; return $this->configCacheFactory;
} }
private static function getCompiledRoutes(string $path): array
{
if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
self::$cache = null;
}
if (null === self::$cache) {
return require $path;
}
if (isset(self::$cache[$path])) {
return self::$cache[$path];
}
return self::$cache[$path] = require $path;
}
} }

View File

@ -18,11 +18,25 @@ namespace Symfony\Component\Translation\Loader;
*/ */
class PhpFileLoader extends FileLoader class PhpFileLoader extends FileLoader
{ {
private static $cache = [];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function loadResource($resource) protected function loadResource($resource)
{ {
return require $resource; if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
self::$cache = null;
}
if (null === self::$cache) {
return require $resource;
}
if (isset(self::$cache[$resource])) {
return self::$cache[$resource];
}
return self::$cache[$resource] = require $resource;
} }
} }

View File

@ -46,6 +46,7 @@ abstract class AbstractCloner implements ClonerInterface
'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'], 'Doctrine\Common\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castCommonProxy'],
'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'], 'Doctrine\ORM\Proxy\Proxy' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castOrmProxy'],
'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'], 'Doctrine\ORM\PersistentCollection' => ['Symfony\Component\VarDumper\Caster\DoctrineCaster', 'castPersistentCollection'],
'Doctrine\Persistence\ObjectManager' => ['Symfony\Component\VarDumper\Caster\StubCaster', 'cutInternals'],
'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'], 'DOMException' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castException'],
'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'], 'DOMStringList' => ['Symfony\Component\VarDumper\Caster\DOMCaster', 'castLength'],