diff --git a/Command/InfoDoctrineODMCommand.php b/Command/InfoDoctrineODMCommand.php
index 2e184e26..607dd2e5 100644
--- a/Command/InfoDoctrineODMCommand.php
+++ b/Command/InfoDoctrineODMCommand.php
@@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new Exception(
'You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. ' .
'Create a class inside the Document namespace of any of your bundles and provide ' .
- 'mapping information for it with Annotations directly in the classes doc blocks ' .
+ 'mapping information for it with Attributes directly in the classes doc blocks ' .
'or with XML in your bundles Resources/config/doctrine/metadata/mongodb directory.'
);
}
diff --git a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
index d7e39f3c..0b51e346 100644
--- a/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
+++ b/DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
@@ -4,7 +4,6 @@
namespace Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler;
-use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
@@ -93,27 +92,6 @@ public static function createPhpMappingDriver(array $mappings, array $managerPar
return new DoctrineMongoDBMappingsPass($driver, $mappings, $managerParameters, $enabledParameter, $aliasMap);
}
- /**
- * @param array $namespaces List of namespaces that are handled with annotation mapping
- * @param array $directories List of directories to look for annotation mapping files
- * @param string[] $managerParameters List of parameters that could which object manager name
- * your bundle uses. This compiler pass will automatically
- * append the parameter name for the default entity manager
- * to this list.
- * @param string|false $enabledParameter Service container parameter that must be present to
- * enable the mapping. Set to false to not do any check,
- * optional.
- * @param string[] $aliasMap Map of alias to namespace.
- *
- * @return DoctrineMongoDBMappingsPass
- */
- public static function createAnnotationMappingDriver(array $namespaces, array $directories, array $managerParameters, $enabledParameter = false, array $aliasMap = [])
- {
- $driver = new Definition(AnnotationDriver::class, [new Reference('annotation_reader'), $directories]);
-
- return new DoctrineMongoDBMappingsPass($driver, $namespaces, $managerParameters, $enabledParameter, $aliasMap);
- }
-
/**
* @param array $namespaces List of namespaces that are handled with attribute mapping
* @param array $directories List of directories to look for attribute mapping files
diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php
index df23fe9d..6206324b 100644
--- a/DependencyInjection/DoctrineMongoDBExtension.php
+++ b/DependencyInjection/DoctrineMongoDBExtension.php
@@ -479,9 +479,8 @@ private function normalizeDriverOptions(array $connection): array
* mappings:
* MyBundle1: ~
* MyBundle2: xml
- * MyBundle3: { type: annotation, dir: Documents/ }
- * MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
- * MyBundle5:
+ * MyBundle3: { type: xml, dir: Resources/config/doctrine/mapping }
+ * MyBundle4:
* type: xml
* dir: [bundle-mappings1/, bundle-mappings2/]
* alias: BundleAlias
diff --git a/Resources/config/mongodb.xml b/Resources/config/mongodb.xml
index b3bb407e..d812311e 100644
--- a/Resources/config/mongodb.xml
+++ b/Resources/config/mongodb.xml
@@ -31,7 +31,6 @@
Doctrine\Persistence\Mapping\Driver\MappingDriverChain
- Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver
Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver
Doctrine\ODM\MongoDB\Mapping\Driver\AttributeReader
Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver
@@ -112,11 +111,6 @@
-
-
- %doctrine_mongodb.odm.document_dirs%
-
-
%doctrine_mongodb.odm.document_dirs%
diff --git a/Resources/doc/config.rst b/Resources/doc/config.rst
index 7e5f19c9..5435a0a7 100644
--- a/Resources/doc/config.rst
+++ b/Resources/doc/config.rst
@@ -126,7 +126,7 @@ Explicit definition of all the mapped documents is the only necessary
configuration for the ODM and there are several configuration options that you
can control. The following configuration options exist for a mapping:
-- ``type`` One of ``annotation``, ``attribute``, ``xml``, ``php`` or ``staticphp``.
+- ``type`` One of ``attribute``, ``xml``, ``php`` or ``staticphp``.
This specifies which type of metadata type your mapping uses.
- ``dir`` Path to the mapping or document files (depending on the driver). If
@@ -157,12 +157,12 @@ follow these conventions:
1. Put all your documents in a directory ``Document/`` inside your project. For
example ``src/Document/``.
-2. If you are using xml, yml or php mapping put all your configuration files
+2. If you are using xml or php mapping put all your configuration files
into either the ``config/doctrine/`` directory (requires Symfony 5.4 or
later) or the ``Resources/config/doctrine/`` directory
suffixed with mongodb.xml, mongodb.yml or mongodb.php respectively.
-3. Annotations are assumed if a ``Document/`` but no
+3. Attributes are assumed if a ``Document/`` but no
``config/doctrine/`` or ``Resources/config/doctrine/`` directory is found.
The following configuration shows a bunch of mapping examples:
@@ -178,9 +178,8 @@ The following configuration shows a bunch of mapping examples:
MyBundle1: ~
MyBundle2: xml
MyBundle3: { type: attribute, dir: Documents/ }
- MyBundle4: { type: annotation, dir: Documents/Legacy/ }
- MyBundle5: { type: xml, dir: Resources/config/doctrine/mapping }
- MyBundle6:
+ MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
+ MyBundle5:
type: xml
dir: my-bundle-mappings-dir
alias: BundleAlias
@@ -203,11 +202,9 @@ The following configuration shows a bunch of mapping examples:
-
-
-
-
-
+
+
+
id;
- }
-
- public function getEmail()
- {
- return $this->email;
- }
-
- public function setEmail($email)
- {
- $this->email = $email;
- }
-
- public function getPassword()
- {
- return $this->password;
- }
-
- // stupid simple encryption (please don't copy it!)
- public function setPassword($password)
- {
- $this->password = sha1($password);
- }
- }
-
.. code-block:: php-attributes
// src/Document/User.php
diff --git a/Resources/doc/first_steps.rst b/Resources/doc/first_steps.rst
index c861496e..5fca0e27 100644
--- a/Resources/doc/first_steps.rst
+++ b/Resources/doc/first_steps.rst
@@ -46,7 +46,7 @@ For Doctrine to be able to do this, you have to create "metadata", or
configuration that tells Doctrine exactly how the ``Product`` class and its
properties should be *mapped* to MongoDB. This metadata can be specified
in a number of different formats including XML or directly inside the
-``Product`` class via annotations or PHP 8 attributes:
+``Product`` class via PHP 8 attributes:
.. versionadded:: 4.4
@@ -54,34 +54,6 @@ in a number of different formats including XML or directly inside the
.. configuration-block::
- .. code-block:: php-annotations
-
- // src/Document/Product.php
- namespace App\Document;
-
- use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
-
- /**
- * @MongoDB\Document
- */
- class Product
- {
- /**
- * @MongoDB\Id
- */
- protected $id;
-
- /**
- * @MongoDB\Field(type="string")
- */
- protected $name;
-
- /**
- * @MongoDB\Field(type="float")
- */
- protected $price;
- }
-
.. code-block:: php-attributes
// src/Document/Product.php
@@ -120,11 +92,11 @@ in a number of different formats including XML or directly inside the
.. seealso::
You can also check out Doctrine's `Basic Mapping Documentation`_ for
- all details about mapping information. If you use annotations, you'll
- need to prepend all annotations with ``MongoDB\`` (e.g. ``MongoDB\String``),
+ all details about mapping information. If you use attributes, you'll
+ need to prepend all attributes with ``MongoDB\`` (e.g. ``MongoDB\String``),
which is not shown in Doctrine's documentation. You'll also need to include
the ``use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;`` statement,
- which *imports* the ``MongoDB`` annotations prefix.
+ which *imports* the ``MongoDB`` attributes prefix.
Persisting Objects to MongoDB
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -559,22 +531,6 @@ To do this, add the name of the repository class to your mapping definition.
.. configuration-block::
- .. code-block:: php-annotations
-
- // src/Document/Product.php
- namespace App\Document;
-
- use App\Repository\ProductRepository;
- use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
-
- /**
- * @MongoDB\Document(repositoryClass=ProductRepository::class)
- */
- class Product
- {
- // ...
- }
-
.. code-block:: php-attributes
// src/Document/Product.php
diff --git a/Tests/Command/InfoDoctrineODMCommandTest.php b/Tests/Command/InfoDoctrineODMCommandTest.php
index 98c66cd2..ced62008 100644
--- a/Tests/Command/InfoDoctrineODMCommandTest.php
+++ b/Tests/Command/InfoDoctrineODMCommandTest.php
@@ -35,7 +35,7 @@ public function testExecuteWithDocumentManagerWithoutDocuments(): void
$commandTester = new CommandTester($command);
$this->expectException(Throwable::class);
- $this->expectExceptionMessage('You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. Create a class inside the Document namespace of any of your bundles and provide mapping information for it with Annotations directly in the classes doc blocks or with XML in your bundles Resources/config/doctrine/metadata/mongodb directory');
+ $this->expectExceptionMessage('You do not have any mapped Doctrine MongoDB ODM documents for any of your bundles. Create a class inside the Document namespace of any of your bundles and provide mapping information for it with Attributes directly in the classes doc blocks or with XML in your bundles Resources/config/doctrine/metadata/mongodb directory');
$commandTester->execute(['--dm' => 'command_test_without_documents']);
}
diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php
index 03fe7696..ae2e4c94 100644
--- a/Tests/ContainerTest.php
+++ b/Tests/ContainerTest.php
@@ -5,10 +5,8 @@
namespace Doctrine\Bundle\MongoDBBundle\Tests;
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
-use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
-use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use function sys_get_temp_dir;
@@ -32,7 +30,6 @@ protected function setUp(): void
'kernel.container_class' => Container::class,
]));
- $this->container->setDefinition('annotation_reader', new Definition(AnnotationReader::class));
$this->extension = new DoctrineMongoDBExtension();
}
diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
index 386538ce..1376052c 100644
--- a/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
+++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
@@ -18,7 +18,6 @@
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
-use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use MongoDB\Client;
@@ -64,7 +63,6 @@ public function testDependencyInjectionConfigurationDefaults(): void
$this->assertEquals('Memcache', $container->getParameter('doctrine_mongodb.odm.cache.memcache_instance.class'));
$this->assertEquals(XcacheCache::class, $container->getParameter('doctrine_mongodb.odm.cache.xcache.class'));
$this->assertEquals(MappingDriverChain::class, $container->getParameter('doctrine_mongodb.odm.metadata.driver_chain.class'));
- $this->assertEquals(AnnotationDriver::class, $container->getParameter('doctrine_mongodb.odm.metadata.annotation.class'));
$this->assertEquals(AttributeDriver::class, $container->getParameter('doctrine_mongodb.odm.metadata.attribute.class'));
$this->assertEquals(XmlDriver::class, $container->getParameter('doctrine_mongodb.odm.metadata.xml.class'));
@@ -320,20 +318,6 @@ public function testNewBundleStructureXmlBundleMappingDetection(): void
$this->assertEquals('Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\NewXmlBundle\Document', $calls[0][1][1]);
}
- public function testAnnotationsBundleMappingDetection(): void
- {
- $container = $this->getContainer('AnnotationsBundle');
- $loader = new DoctrineMongoDBExtension();
- $config = DoctrineMongoDBExtensionTest::buildConfiguration(
- ['document_managers' => ['default' => ['mappings' => ['AnnotationsBundle' => []]]]],
- );
- $loader->load($config, $container);
-
- $calls = $container->getDefinition('doctrine_mongodb.odm.default_metadata_driver')->getMethodCalls();
- $this->assertEquals('doctrine_mongodb.odm.default_annotation_metadata_driver', (string) $calls[0][1][0]);
- $this->assertEquals('Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\AnnotationsBundle\Document', $calls[0][1][1]);
- }
-
public function testAttributesBundleMappingDetection(): void
{
if (! class_exists(AttributeDriver::class)) {
diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php
index a647d431..91dee4d5 100644
--- a/Tests/DependencyInjection/ConfigurationTest.php
+++ b/Tests/DependencyInjection/ConfigurationTest.php
@@ -165,10 +165,6 @@ public function testFullConfiguration(array $config): void
],
'mappings' => [
'FooBundle' => [
- 'type' => 'annotation',
- 'mapping' => true,
- ],
- 'BarBundle' => [
'type' => 'attribute',
'mapping' => true,
],
@@ -191,7 +187,7 @@ public function testFullConfiguration(array $config): void
'metadata_cache_driver' => ['type' => 'apc'],
'mappings' => [
'BarBundle' => [
- 'type' => 'yml',
+ 'type' => 'xml',
'dir' => '%kernel.cache_dir%',
'prefix' => 'prefix_val',
'alias' => 'alias_val',
diff --git a/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php b/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
deleted file mode 100644
index dadeff01..00000000
--- a/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/AnnotationsBundle.php
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
+
fooClass
host_val
@@ -109,7 +108,7 @@
>
__DIR__ . '/../../../../',
'kernel.container_class' => Container::class,
]));
- $this->container->setDefinition('annotation_reader', new Definition(AnnotationReader::class));
- $extension = new DoctrineMongoDBExtension();
+ $extension = new DoctrineMongoDBExtension();
$this->container->registerExtension($extension);
$extension->load([
diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md
index 7692f3be..e8523d94 100644
--- a/UPGRADE-5.0.md
+++ b/UPGRADE-5.0.md
@@ -10,4 +10,5 @@ UPGRADE FROM 4.x to 5.0
`Doctrine\Bundle\MongoDBBundle\Command\DoctrineODMCommand` have been
removed without replacement.
* The `Doctrine\Bundle\MongoDBBundle\Command\DoctrineODMCommand` class is now
- `@internal`, you should not extend from this class.
\ No newline at end of file
+ `@internal`, you should not extend from this class.
+* Remove support of Annotation mapping, you should use Attributes or XML instead.
diff --git a/composer.json b/composer.json
index be732051..59652ded 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,6 @@
"require": {
"php": "^8.1",
"ext-mongodb": "^1.5",
- "doctrine/annotations": "^1.13 || ^2.0",
"doctrine/mongodb-odm": "^2.3",
"doctrine/persistence": "^2.2 || ^3.0",
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",