Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support of annotations #793

Merged
merged 1 commit into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Command/InfoDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);
}
Expand Down
22 changes: 0 additions & 22 deletions DependencyInjection/Compiler/DoctrineMongoDBMappingsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private function normalizeDriverOptions(array $connection): array
* mappings:
* MyBundle1: ~
* MyBundle2: xml
* MyBundle3: { type: annotation, dir: Documents/ }
GromNaN marked this conversation as resolved.
Show resolved Hide resolved
* MyBundle3: { type: attribute }
* MyBundle4: { type: xml, dir: Resources/config/doctrine/mapping }
* MyBundle5:
* type: xml
Expand Down
6 changes: 0 additions & 6 deletions Resources/config/mongodb.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

<!-- metadata -->
<parameter key="doctrine_mongodb.odm.metadata.driver_chain.class">Doctrine\Persistence\Mapping\Driver\MappingDriverChain</parameter>
<parameter key="doctrine_mongodb.odm.metadata.annotation.class">Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver</parameter>
<parameter key="doctrine_mongodb.odm.metadata.attribute.class">Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver</parameter>
<parameter key="doctrine_mongodb.odm.metadata.attribute_reader.class">Doctrine\ODM\MongoDB\Mapping\Driver\AttributeReader</parameter>
<parameter key="doctrine_mongodb.odm.metadata.xml.class">Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver</parameter>
Expand Down Expand Up @@ -112,11 +111,6 @@

<!-- metadata -->
<service id="doctrine_mongodb.odm.metadata.chain" class="%doctrine_mongodb.odm.metadata.driver_chain.class%" />
<service id="doctrine_mongodb.odm.metadata.annotation" class="%doctrine_mongodb.odm.metadata.annotation.class%">
<argument type="service" id="doctrine_mongodb.odm.metadata.annotation_reader" />
<argument>%doctrine_mongodb.odm.document_dirs%</argument>
</service>
<service id="doctrine_mongodb.odm.metadata.annotation_reader" alias="annotation_reader" />
<service id="doctrine_mongodb.odm.metadata.attribute" class="%doctrine_mongodb.odm.metadata.attribute.class%">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if these services are necessary, I'll try to remove them in another PR

<argument>%doctrine_mongodb.odm.document_dirs%</argument>
<argument type="service" id="doctrine_mongodb.odm.metadata.attribute_reader" />
Expand Down
19 changes: 8 additions & 11 deletions Resources/doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -203,11 +202,9 @@ The following configuration shows a bunch of mapping examples:
<doctrine_mongodb:config>
<doctrine_mongodb:document-manager id="default">
<doctrine_mongodb:mapping name="MyBundle1" />
<doctrine_mongodb:mapping name="MyBundle2" type="yml" />
<doctrine_mongodb:mapping name="MyBundle3" type="attribute" dir="Documents/" />
<doctrine_mongodb:mapping name="MyBundle4" type="annotation" dir="Documents/Legacy/" />
<doctrine_mongodb:mapping name="MyBundle5" type="xml" dir="Resources/config/doctrine/mapping" />
<doctrine_mongodb:mapping name="MyBundle6" type="xml" dir="my-bundle-mappings-dir" alias="BundleAlias" />
<doctrine_mongodb:mapping name="MyBundle2" type="attribute" dir="Documents/" />
<doctrine_mongodb:mapping name="MyBundle3" type="xml" dir="Resources/config/doctrine/mapping" />
<doctrine_mongodb:mapping name="MyBundle4" type="xml" dir="my-bundle-mappings-dir" alias="BundleAlias" />
<doctrine_mongodb:mapping name="doctrine_extensions"
type="xml"
dir="%kernel.project_dir%/src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Documents"
Expand Down
60 changes: 0 additions & 60 deletions Resources/doc/cookbook/registration_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,6 @@ We begin this tutorial with the model for a ``User`` document:

.. configuration-block::

.. code-block:: php-annotations

// src/Document/User.php
namespace App\Document;

use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @MongoDB\Document(collection="users")
* @MongoDB\Unique(fields="email")
*/
class User
{
/**
* @MongoDB\Id
*/
protected $id;

/**
* @MongoDB\Field(type="string")
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $email;

/**
* @MongoDB\Field(type="string")
* @Assert\NotBlank()
*/
protected $password;

public function getId()
{
return $this->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
Expand Down
52 changes: 4 additions & 48 deletions Resources/doc/first_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,42 +46,14 @@ 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

The attribute mapping support was added in Doctrine MongoDB ODM Bundle 4.4 and requires PHP 8.0 or newer.

.. 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
Expand Down Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/InfoDoctrineODMCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand Down
3 changes: 0 additions & 3 deletions Tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
16 changes: 0 additions & 16 deletions Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'));

Expand Down Expand Up @@ -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)) {
Expand Down
6 changes: 1 addition & 5 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ public function testFullConfiguration(array $config): void
],
'mappings' => [
'FooBundle' => [
'type' => 'annotation',
'mapping' => true,
],
'BarBundle' => [
'type' => 'attribute',
'mapping' => true,
],
Expand All @@ -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',
Expand Down

This file was deleted.

This file was deleted.

Loading