From d73fd1e2f273b933cd68fa62ffcaea4bddaac29d Mon Sep 17 00:00:00 2001
From: Fran Moreno <franmomu@gmail.com>
Date: Mon, 26 Dec 2022 16:28:16 +0100
Subject: [PATCH] make doctrine/annotations dependency optional

---
 UPGRADE-2.5.md                              |  5 +++++
 composer.json                               |  6 +++++-
 docs/en/reference/annotations-reference.rst |  5 +++++
 docs/en/reference/basic-mapping.rst         | 20 ++++++++++++++------
 docs/en/reference/metadata-drivers.rst      |  5 +++--
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/UPGRADE-2.5.md b/UPGRADE-2.5.md
index 86de15af2d..3e657a0412 100644
--- a/UPGRADE-2.5.md
+++ b/UPGRADE-2.5.md
@@ -11,3 +11,8 @@ ODM supports doctrine/collections 2.x along 1.x. Please note that we added
 `findFirst(...)` and `reduce(...)` methods to comply with the new `Collection`
 interface. Make sure signatures of new methods comply with your own ones,
 should you have implemented such methods before.
+
+## `doctrine/annotations` is optional
+
+ODM no longer requires `doctrine/annotations` to be installed. If you're using
+annotations for mapping, you will need to install `doctrine/annotations`.
diff --git a/composer.json b/composer.json
index 5fd9bfe34d..9cfb24f6c6 100644
--- a/composer.json
+++ b/composer.json
@@ -23,7 +23,6 @@
     "require": {
         "php": "^7.4 || ^8.0",
         "ext-mongodb": "^1.5",
-        "doctrine/annotations": "^1.12 || ^2.0",
         "doctrine/cache": "^1.11 || ^2.0",
         "doctrine/collections": "^1.5 || ^2.0",
         "doctrine/event-manager": "^1.0 || ^2.0",
@@ -39,6 +38,7 @@
     },
     "require-dev": {
         "ext-bcmath": "*",
+        "doctrine/annotations": "^1.12 || ^2.0",
         "doctrine/coding-standard": "^11.0",
         "jmikola/geojson": "^1.0",
         "phpbench/phpbench": "^1.0.0@dev",
@@ -49,7 +49,11 @@
         "symfony/cache": "^4.4 || ^5.0 || ^6.0",
         "vimeo/psalm": "^4.30.0"
     },
+    "conflict": {
+        "doctrine/annotations": "<1.12 || >=3.0"
+    },
     "suggest": {
+        "doctrine/annotations": "For annotation mapping support",
         "ext-bcmath": "Decimal128 type support"
     },
     "autoload": {
diff --git a/docs/en/reference/annotations-reference.rst b/docs/en/reference/annotations-reference.rst
index c30676fabb..881e98207a 100644
--- a/docs/en/reference/annotations-reference.rst
+++ b/docs/en/reference/annotations-reference.rst
@@ -1,6 +1,11 @@
 Annotations Reference
 =====================
 
+.. note::
+
+    To be able to use annotations, you will have to install an extra
+    package called ``doctrine/annotations``.
+
 In this chapter a reference of every Doctrine 2 ODM Annotation is
 given with short explanations on their context and usage.
 
diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst
index 9442604829..1c204751ff 100644
--- a/docs/en/reference/basic-mapping.rst
+++ b/docs/en/reference/basic-mapping.rst
@@ -32,6 +32,11 @@ document mapping metadata:
 Introduction to Docblock Annotations
 ------------------------------------
 
+.. note::
+
+    To be able to use annotations, you will have to install an extra
+    package called ``doctrine/annotations``.
+
 You've probably used docblock annotations in some form already,
 most likely to provide documentation metadata for a tool like
 ``PHPDocumentor`` (@author, @link, ...). Docblock annotations are a
@@ -44,12 +49,15 @@ chances of clashes with other docblock annotations, the Doctrine
 docblock annotations feature an alternative syntax that is heavily
 inspired by the Annotation syntax introduced in Java 5.
 
-The implementation of these enhanced docblock annotations is
-located in the ``Doctrine\Common\Annotations`` namespace and
-therefore part of the Common package. Doctrine docblock annotations
-support namespaces and nested annotations among other things. The
-Doctrine MongoDB ODM defines its own set of docblock annotations
-for supplying object document mapping metadata.
+The implementation of these enhanced docblock annotations is located in
+the ``doctrine/annotations`` package, but in the
+``Doctrine\Common\Annotations`` namespace for backwards compatibility
+reasons. Note that ``doctrine/annotations`` is not required by Doctrine
+MongoDB ODM, and you will need to require that package if you want to use
+annotations. Doctrine MongoDB ODM docblock annotations support namespaces and
+nested annotations among other things. The Doctrine MongoDB ODM defines its
+own set of docblock annotations for supplying object-relational mapping
+metadata.
 
 .. note::
 
diff --git a/docs/en/reference/metadata-drivers.rst b/docs/en/reference/metadata-drivers.rst
index f52a2dcb65..7c5e18ce09 100644
--- a/docs/en/reference/metadata-drivers.rst
+++ b/docs/en/reference/metadata-drivers.rst
@@ -37,8 +37,9 @@ a document.
 
         $em->getConfiguration()->setMetadataCacheImpl(new ApcCache());
 
-If you want to use one of the included core metadata drivers you
-just need to configure it. All the drivers are in the
+If you want to use one of the included core metadata drivers you need to
+configure it. If you pick the annotation driver, you will additionally
+need to install ``doctrine/annotations``. All the drivers are in the
 ``Doctrine\ODM\MongoDB\Mapping\Driver`` namespace:
 
 .. code-block:: php