From ce5f39b09986e63811696f531f38ac6d9bb260c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Fri, 14 Feb 2020 19:40:15 +0100 Subject: [PATCH] Address deprecations from persistence library A backwards-compatibility layer has been added to persistence to help consumers move to the new namespacing. It is based on class aliases, which means the type declaration changes should not be a BC-break: types are the same. See doctrine/persistence#71 This means: - using the new namespaces - adding autoload calls for new types to types that may be extended and use persistence types in methods signatures for which compatibility checks may happen, so that signature compatibility is recognized by old versions of php. More details on this at https://dev.to/greg0ire/how-to-deprecate-a-type-in-php-48cf Fixes #616 as a side effect, but the real fix is at https://github.com/symfony/symfony/pull/35728 --- CacheWarmer/HydratorCacheWarmer.php | 2 +- CacheWarmer/PersistentCollectionCacheWarmer.php | 2 +- CacheWarmer/ProxyCacheWarmer.php | 2 +- .../Compiler/DoctrineMongoDBMappingsPass.php | 6 +++--- Form/ChoiceList/MongoDBQueryBuilderLoader.php | 2 +- Form/DoctrineMongoDBExtension.php | 2 +- Form/DoctrineMongoDBTypeGuesser.php | 4 ++-- Form/Type/DocumentType.php | 5 ++++- Repository/ContainerRepositoryFactory.php | 2 +- Repository/ServiceRepositoryTrait.php | 2 +- Resources/config/mongodb.xml | 2 +- Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php | 2 +- Tests/DependencyInjection/AbstractMongoDBExtensionTest.php | 2 +- .../DependentOnRequiredConstructorArgsFixtures.php | 2 +- Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php | 2 +- .../DataFixtures/RequiredConstructorArgsFixtures.php | 2 +- .../FooBundle/DataFixtures/WithDependenciesFixtures.php | 2 +- Tests/Form/Type/DocumentTypeTest.php | 2 +- Tests/Form/Type/TypeGuesserTest.php | 2 +- Tests/Mapping/Driver/AbstractDriverTest.php | 6 +++--- composer.json | 1 + 21 files changed, 29 insertions(+), 25 deletions(-) diff --git a/CacheWarmer/HydratorCacheWarmer.php b/CacheWarmer/HydratorCacheWarmer.php index 7cccb33b..5209ee91 100644 --- a/CacheWarmer/HydratorCacheWarmer.php +++ b/CacheWarmer/HydratorCacheWarmer.php @@ -4,9 +4,9 @@ namespace Doctrine\Bundle\MongoDBBundle\CacheWarmer; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ManagerRegistry; use RuntimeException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; diff --git a/CacheWarmer/PersistentCollectionCacheWarmer.php b/CacheWarmer/PersistentCollectionCacheWarmer.php index 9a36e279..30c52111 100644 --- a/CacheWarmer/PersistentCollectionCacheWarmer.php +++ b/CacheWarmer/PersistentCollectionCacheWarmer.php @@ -4,9 +4,9 @@ namespace Doctrine\Bundle\MongoDBBundle\CacheWarmer; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ManagerRegistry; use RuntimeException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index 99b84bbe..101904a0 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -4,10 +4,10 @@ namespace Doctrine\Bundle\MongoDBBundle\CacheWarmer; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\Persistence\ManagerRegistry; use RuntimeException; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; diff --git a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php index 75b0a764..27527b76 100644 --- a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php +++ b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php @@ -4,11 +4,11 @@ namespace Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler; -use Doctrine\Common\Persistence\Mapping\Driver\PHPDriver; -use Doctrine\Common\Persistence\Mapping\Driver\StaticPHPDriver; -use Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver; +use Doctrine\Persistence\Mapping\Driver\PHPDriver; +use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver; +use Doctrine\Persistence\Mapping\Driver\SymfonyFileLocator; use Symfony\Bridge\Doctrine\DependencyInjection\CompilerPass\RegisterMappingsPass; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; diff --git a/Form/ChoiceList/MongoDBQueryBuilderLoader.php b/Form/ChoiceList/MongoDBQueryBuilderLoader.php index de0e52a0..00b95434 100644 --- a/Form/ChoiceList/MongoDBQueryBuilderLoader.php +++ b/Form/ChoiceList/MongoDBQueryBuilderLoader.php @@ -5,8 +5,8 @@ namespace Doctrine\Bundle\MongoDBBundle\Form\ChoiceList; use Closure; -use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ODM\MongoDB\Query\Builder; +use Doctrine\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; use Symfony\Component\Form\Exception\UnexpectedTypeException; use function array_values; diff --git a/Form/DoctrineMongoDBExtension.php b/Form/DoctrineMongoDBExtension.php index 133e37ba..5d9863e7 100644 --- a/Form/DoctrineMongoDBExtension.php +++ b/Form/DoctrineMongoDBExtension.php @@ -4,7 +4,7 @@ namespace Doctrine\Bundle\MongoDBBundle\Form; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\Form\AbstractExtension; /** diff --git a/Form/DoctrineMongoDBTypeGuesser.php b/Form/DoctrineMongoDBTypeGuesser.php index c8d92bb1..92999ce0 100644 --- a/Form/DoctrineMongoDBTypeGuesser.php +++ b/Form/DoctrineMongoDBTypeGuesser.php @@ -5,8 +5,8 @@ namespace Doctrine\Bundle\MongoDBBundle\Form; use Doctrine\Bundle\MongoDBBundle\Form\Type\DocumentType; -use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\Common\Persistence\Mapping\MappingException; +use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Persistence\Mapping\MappingException; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; diff --git a/Form/Type/DocumentType.php b/Form/Type/DocumentType.php index 556af655..a9c5274f 100644 --- a/Form/Type/DocumentType.php +++ b/Form/Type/DocumentType.php @@ -5,12 +5,13 @@ namespace Doctrine\Bundle\MongoDBBundle\Form\Type; use Doctrine\Bundle\MongoDBBundle\Form\ChoiceList\MongoDBQueryBuilderLoader; -use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ObjectManager; use InvalidArgumentException; use Symfony\Bridge\Doctrine\Form\Type\DoctrineType; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; +use function interface_exists; /** * Form type for a MongoDB document @@ -83,3 +84,5 @@ public function getName() return $this->getBlockPrefix(); } } + +interface_exists(ObjectManager::class); diff --git a/Repository/ContainerRepositoryFactory.php b/Repository/ContainerRepositoryFactory.php index ca036644..7e246850 100644 --- a/Repository/ContainerRepositoryFactory.php +++ b/Repository/ContainerRepositoryFactory.php @@ -5,11 +5,11 @@ namespace Doctrine\Bundle\MongoDBBundle\Repository; use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass; -use Doctrine\Common\Persistence\ObjectRepository; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Repository\RepositoryFactory; +use Doctrine\Persistence\ObjectRepository; use Psr\Container\ContainerInterface; use RuntimeException; use function class_exists; diff --git a/Repository/ServiceRepositoryTrait.php b/Repository/ServiceRepositoryTrait.php index 46ded4aa..cb2f4d13 100644 --- a/Repository/ServiceRepositoryTrait.php +++ b/Repository/ServiceRepositoryTrait.php @@ -4,8 +4,8 @@ namespace Doctrine\Bundle\MongoDBBundle\Repository; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ManagerRegistry; use LogicException; use function sprintf; diff --git a/Resources/config/mongodb.xml b/Resources/config/mongodb.xml index af58039c..82e43695 100644 --- a/Resources/config/mongodb.xml +++ b/Resources/config/mongodb.xml @@ -30,7 +30,7 @@ Doctrine\Common\Cache\XcacheCache - Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain + Doctrine\Persistence\Mapping\Driver\MappingDriverChain Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver diff --git a/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php b/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php index 0c46cba5..b88ad310 100644 --- a/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php +++ b/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php @@ -6,9 +6,9 @@ use Doctrine\Bundle\MongoDBBundle\CacheWarmer\PersistentCollectionCacheWarmer; use Doctrine\Bundle\MongoDBBundle\Tests\TestCase; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionGenerator; +use Doctrine\Persistence\ManagerRegistry; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use function sys_get_temp_dir; diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php index 51e8c2e6..015532c3 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php @@ -13,10 +13,10 @@ use Doctrine\Common\Cache\MemcachedCache; use Doctrine\Common\Cache\XcacheCache; use Doctrine\Common\EventSubscriber; -use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain; use Doctrine\ODM\MongoDB\Configuration; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use MongoDB\Client; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit_Framework_AssertionFailedError; diff --git a/Tests/Fixtures/FooBundle/DataFixtures/DependentOnRequiredConstructorArgsFixtures.php b/Tests/Fixtures/FooBundle/DataFixtures/DependentOnRequiredConstructorArgsFixtures.php index 7f2cee1e..0a1c5d11 100644 --- a/Tests/Fixtures/FooBundle/DataFixtures/DependentOnRequiredConstructorArgsFixtures.php +++ b/Tests/Fixtures/FooBundle/DataFixtures/DependentOnRequiredConstructorArgsFixtures.php @@ -6,7 +6,7 @@ use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; use Doctrine\Common\DataFixtures\DependentFixtureInterface; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; class DependentOnRequiredConstructorArgsFixtures implements ODMFixtureInterface, DependentFixtureInterface { diff --git a/Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php b/Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php index e1e63dbc..8d66527e 100644 --- a/Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php +++ b/Tests/Fixtures/FooBundle/DataFixtures/OtherFixtures.php @@ -6,7 +6,7 @@ use Doctrine\Bundle\MongoDBBundle\Fixture\FixtureGroupInterface; use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; class OtherFixtures implements ODMFixtureInterface, FixtureGroupInterface { diff --git a/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php b/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php index e1a1fdd6..32c99f66 100644 --- a/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php +++ b/Tests/Fixtures/FooBundle/DataFixtures/RequiredConstructorArgsFixtures.php @@ -5,7 +5,7 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\FooBundle\DataFixtures; use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; class RequiredConstructorArgsFixtures implements ODMFixtureInterface { diff --git a/Tests/Fixtures/FooBundle/DataFixtures/WithDependenciesFixtures.php b/Tests/Fixtures/FooBundle/DataFixtures/WithDependenciesFixtures.php index 52398a0c..3c9cfc32 100644 --- a/Tests/Fixtures/FooBundle/DataFixtures/WithDependenciesFixtures.php +++ b/Tests/Fixtures/FooBundle/DataFixtures/WithDependenciesFixtures.php @@ -7,7 +7,7 @@ use Doctrine\Bundle\MongoDBBundle\Fixture\FixtureGroupInterface; use Doctrine\Bundle\MongoDBBundle\Fixture\ODMFixtureInterface; use Doctrine\Common\DataFixtures\DependentFixtureInterface; -use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\Persistence\ObjectManager; class WithDependenciesFixtures implements ODMFixtureInterface, DependentFixtureInterface, FixtureGroupInterface { diff --git a/Tests/Form/Type/DocumentTypeTest.php b/Tests/Form/Type/DocumentTypeTest.php index 8af133d7..4fbfe04f 100644 --- a/Tests/Form/Type/DocumentTypeTest.php +++ b/Tests/Form/Type/DocumentTypeTest.php @@ -9,8 +9,8 @@ use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Category; use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document; use Doctrine\Bundle\MongoDBBundle\Tests\TestCase; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ManagerRegistry; use MongoDB\BSON\ObjectId; use PHPUnit_Framework_MockObject_MockObject; use Symfony\Component\Form\AbstractType; diff --git a/Tests/Form/Type/TypeGuesserTest.php b/Tests/Form/Type/TypeGuesserTest.php index f656b56b..0c4a0c3d 100644 --- a/Tests/Form/Type/TypeGuesserTest.php +++ b/Tests/Form/Type/TypeGuesserTest.php @@ -9,8 +9,8 @@ use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Document; use Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Form\Guesser; use Doctrine\Bundle\MongoDBBundle\Tests\TestCase; -use Doctrine\Common\Persistence\ManagerRegistry; use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit_Framework_MockObject_MockObject; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Test\TypeTestCase; diff --git a/Tests/Mapping/Driver/AbstractDriverTest.php b/Tests/Mapping/Driver/AbstractDriverTest.php index 4f738697..03441bfe 100644 --- a/Tests/Mapping/Driver/AbstractDriverTest.php +++ b/Tests/Mapping/Driver/AbstractDriverTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\Mapping\Driver; -use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; +use Doctrine\Persistence\Mapping\Driver\FileDriver; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -38,7 +38,7 @@ public function testFindMappingFileInSubnamespace() } /** - * @expectedException Doctrine\Common\Persistence\Mapping\MappingException + * @expectedException Doctrine\Persistence\Mapping\MappingException */ public function testFindMappingFileNamespacedFoundFileNotFound() { @@ -49,7 +49,7 @@ public function testFindMappingFileNamespacedFoundFileNotFound() } /** - * @expectedException Doctrine\Common\Persistence\Mapping\MappingException + * @expectedException Doctrine\Persistence\Mapping\MappingException */ public function testFindMappingNamespaceNotFound() { diff --git a/composer.json b/composer.json index 55d08f00..4c93cd51 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "php": "^7.2", "doctrine/annotations": "^1.2", "doctrine/mongodb-odm": "^2.0.0", + "doctrine/persistence": "^1.3.6", "psr/log": "^1.0", "symfony/console": "^4.3.3|^5.0", "symfony/dependency-injection": "^4.3.3|^5.0",