Skip to content

Commit fd80856

Browse files
committed
Make Annotation classes extend the Attribute classes
The Attribute classes cannot be used as Annotation Move QueryType enum to the Mapping namespace Keep the tests on the Annotations namespace
1 parent 15f6084 commit fd80856

File tree

447 files changed

+659
-1441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

447 files changed

+659
-1441
lines changed

UPGRADE-2.16.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
## Attribute namespaces
44

55
Doctrine annotations are already deprecated in favor of PHP attributes.
6-
As of MongoDB ODM 2.16, the attribute namespaces have been changed from
6+
As of MongoDB ODM 2.16, the namespace of attribute classes has been changed from
77
`Doctrine\ODM\MongoDB\Mapping\Annotations` to `Doctrine\ODM\MongoDB\Mapping\Attribute`.
8-
The old annotation namespaces continue to work for the time being, but they are
9-
deprecated and will be removed in 3.0.
8+
The old classes continue to work, but they are deprecated and will be removed in 3.0.
109

1110
```diff
1211
- use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
@@ -23,6 +22,9 @@ deprecated and will be removed in 3.0.
2322
}
2423
```
2524

25+
The enum `Doctrine\ODM\MongoDB\Mapping\Annotations\QueryType` has been moved to
26+
`Doctrine\ODM\MongoDB\Mapping\Attribute\QueryType`.
27+
2628
## Package `doctrine/cache` no longer required
2729

2830
If you use `Doctrine\ODM\MongoDB\Configuration::getMetadataCacheImpl()`,

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"psr/cache": "^1.0 || ^2.0 || ^3.0",
3939
"symfony/console": "^5.4 || ^6.4 || ^7.0 || ^8.0",
4040
"symfony/deprecation-contracts": "^2.2 || ^3.0",
41+
"symfony/polyfill-php84": "^1.33",
4142
"symfony/var-dumper": "^5.4 || ^6.4 || ^7.0 || ^8.0",
4243
"symfony/var-exporter": "^6.4.1 || ^7.0 || ^8.0"
4344
},

docs/en/cookbook/mapping-classes-to-orm-and-odm.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Now map the same class to the Doctrine MongoDB ODM:
113113
namespace Documents\Blog;
114114
115115
use Documents\Blog\Repository\ODM\BlogPostRepository;
116-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
116+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
117117
118118
#[ODM\Document(repositoryClass: BlogPostRepository::class)]
119119
class BlogPost

docs/en/cookbook/queryable-encryption.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ fields that require encryption.
4747
4848
namespace Documents;
4949
50-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
51-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Encrypt;
52-
use Doctrine\ODM\MongoDB\Mapping\Annotations\EncryptQuery;
50+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
51+
use Doctrine\ODM\MongoDB\Mapping\EncryptQuery;
5352
5453
#[ODM\Document]
5554
class Patient
@@ -69,15 +68,15 @@ fields that require encryption.
6968
* This allows us to find a patient by their exact SSN.
7069
*/
7170
#[ODM\Field(type: 'string')]
72-
#[Encrypt(queryType: EncryptQuery::Equality)]
71+
#[ODM\Encrypt(queryType: EncryptQuery::Equality)]
7372
public string $ssn;
7473
7574
/**
7675
* The entire embedded document is encrypted as an object.
7776
* By not specifying a queryType, we make it non-queryable.
7877
*/
7978
#[ODM\EmbedOne(targetDocument: Billing::class)]
80-
#[Encrypt]
79+
#[ODM\Encrypt]
8180
public Billing $billing;
8281
8382
/**

docs/en/cookbook/time-series-data.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ First, we define the model for our data:
4747
<?php
4848
4949
use DateTimeImmutable;
50-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
50+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
5151
use MongoDB\BSON\ObjectId;
5252
5353
#[ODM\Document]

docs/en/cookbook/validation-of-documents.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ the ``odm:schema:create`` or ``odm:schema:update`` command.
175175
176176
namespace Documents;
177177
178-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
178+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
179179
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
180180
181181
#[ODM\Document]

docs/en/cookbook/vector-search.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ return the same result because Voyage AI uses normalized vectors to length 1.
3636

3737
.. code-block:: php
3838
39-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
39+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
4040
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
4141
use Doctrine\ODM\MongoDB\Types\Type;
4242
use Symfony\AI\Platform\Vector\Vector;

docs/en/reference/annotations-reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Replace the ``@ODM\Document`` annotations with the ``#[ODM\Document]`` attribute
2525

2626
.. code-block:: diff
2727
28-
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
28+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
2929
3030
- /**
3131
- * @ODM\Document

docs/en/reference/attributes-reference.rst

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,14 @@ Example:
368368
369369
<?php
370370
371-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Encrypt;
372-
use Doctrine\ODM\MongoDB\Mapping\Annotations\EncryptQuery;
371+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
372+
use Doctrine\ODM\MongoDB\Mapping\EncryptQuery;
373373
374-
#[Document]
374+
#[ODM\Document]
375375
class Client
376376
{
377-
#[Field]
378-
#[Encrypt(queryType: EncryptQuery::Equality)]
377+
#[ODM\Field]
378+
#[ODM\Encrypt(queryType: EncryptQuery::Equality)]
379379
public string $name;
380380
}
381381
@@ -390,23 +390,23 @@ value in the parent document.
390390
391391
<?php
392392
393-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Encrypt;
393+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
394394
395-
#[Encrypt]
396-
#[EmbeddedDocument]
395+
#[ODM\Encrypt]
396+
#[ODM\EmbeddedDocument]
397397
class CreditCard
398398
{
399-
#[Field]
399+
#[ODM\Field]
400400
public string $number;
401401
402-
#[Field]
402+
#[ODM\Field]
403403
public string $expiryDate;
404404
}
405405
406-
#[Document]
406+
#[ODM\Document]
407407
class User
408408
{
409-
#[EmbedOne(targetDocument: CreditCard::class)]
409+
#[ODM\EmbedOne(targetDocument: CreditCard::class)]
410410
public CreditCard $creditCard;
411411
}
412412
@@ -1476,15 +1476,12 @@ Example:
14761476
.. code-block:: php
14771477
14781478
<?php
1479-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
1480-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
1481-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
1482-
use Doctrine\ODM\MongoDB\Mapping\Annotations\VectorSearchIndex;
1479+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
14831480
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
14841481
use Doctrine\ODM\MongoDB\Types\Type;
14851482
1486-
#[Document(collection: 'vector_embeddings')]
1487-
#[VectorSearchIndex(
1483+
#[ODM\Document(collection: 'vector_embeddings')]
1484+
#[ODM\VectorSearchIndex(
14881485
fields: [
14891486
[
14901487
'type' => 'vector',
@@ -1501,14 +1498,14 @@ Example:
15011498
)]
15021499
class VectorEmbedding
15031500
{
1504-
#[Id]
1501+
#[ODM\Id]
15051502
public ?string $id = null;
15061503
15071504
/** @var list<float> */
1508-
#[Field(type: Type::COLLECTION)]
1505+
#[ODM\Field(type: Type::COLLECTION)]
15091506
public array $plotEmbeddingVoyage3Large = [];
15101507
1511-
#[Field]
1508+
#[ODM\Field]
15121509
public string $category;
15131510
}
15141511

docs/en/reference/basic-mapping.rst

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ to be designated as a document. This can be done through the
5757
5858
namespace Documents;
5959
60-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
60+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
6161
62-
#[Document]
62+
#[ODM\Document]
6363
class User
6464
{
6565
}
@@ -88,9 +88,9 @@ option as follows:
8888
8989
namespace Documents;
9090
91-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
91+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
9292
93-
#[Document(db: 'my_db', collection: 'users')]
93+
#[ODM\Document(db: 'my_db', collection: 'users')]
9494
class User
9595
{
9696
}
@@ -257,13 +257,12 @@ Here is an example:
257257
258258
namespace Documents;
259259
260-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
261-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
260+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
262261
263-
#[Document]
262+
#[ODM\Document]
264263
class User
265264
{
266-
#[Id]
265+
#[ODM\Id]
267266
public string $id;
268267
}
269268
@@ -309,13 +308,12 @@ Here is an example how to manually set a string identifier for your documents:
309308
310309
namespace Documents;
311310
312-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
313-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Id;
311+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
314312
315-
#[Document]
313+
#[ODM\Document]
316314
class MyPersistentClass
317315
{
318-
#[Id(strategy: 'NONE', type: 'string')]
316+
#[ODM\Id(strategy: 'NONE', type: 'string')]
319317
public string $id;
320318
321319
//...
@@ -430,15 +428,14 @@ Example:
430428
431429
namespace Documents;
432430
433-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
434-
use Doctrine\ODM\MongoDB\Mapping\Annotations\Field;
431+
use Doctrine\ODM\MongoDB\Mapping\Attribute as ODM;
435432
436-
#[Document]
433+
#[ODM\Document]
437434
class User
438435
{
439436
// ...
440437
441-
#[Field]
438+
#[ODM\Field]
442439
public string $username;
443440
}
444441

0 commit comments

Comments
 (0)