diff --git a/docs/en/cookbook/simple-search-engine.rst b/docs/en/cookbook/simple-search-engine.rst index 379845037..4ae2b1aeb 100644 --- a/docs/en/cookbook/simple-search-engine.rst +++ b/docs/en/cookbook/simple-search-engine.rst @@ -121,7 +121,8 @@ You can setup a ``Keyword`` document like the following: #[EmbeddedDocument] class Keyword { - #[Field(type: 'string') @Index] + #[Field(type: 'string')] + #[Index] private $keyword; #[Field(type: 'int')] diff --git a/docs/en/cookbook/soft-delete-extension.rst b/docs/en/cookbook/soft-delete-extension.rst index 0790a2ef5..8c1cd3993 100644 --- a/docs/en/cookbook/soft-delete-extension.rst +++ b/docs/en/cookbook/soft-delete-extension.rst @@ -198,7 +198,7 @@ You just need to setup an event listener like the following: $sdm = $args->getSoftDeleteManager(); $document = $args->getDocument(); if ($document instanceof User) { - $sdm->deleteBy(Post:class, ['user.id' => $document->getId()]); + $sdm->deleteBy(Post::class, ['user.id' => $document->getId()]); } } diff --git a/docs/en/reference/aggregation-stage-reference.rst b/docs/en/reference/aggregation-stage-reference.rst index a5e53fb72..be0d7d63c 100644 --- a/docs/en/reference/aggregation-stage-reference.rst +++ b/docs/en/reference/aggregation-stage-reference.rst @@ -377,14 +377,17 @@ pipeline stages. Take the following relationship for example: expr()->gte('$$level', 5), '$$PRUNE', '$$DESCEND' - ) + ); $replaceRoot ------------ diff --git a/docs/en/reference/attributes-reference.rst b/docs/en/reference/attributes-reference.rst index deed201d3..00e35ad6c 100644 --- a/docs/en/reference/attributes-reference.rst +++ b/docs/en/reference/attributes-reference.rst @@ -14,9 +14,12 @@ does not exist. firstName, $this->lastName) = explode(' ', $name); + #[AlsoLoad(['name', 'fullName'])] + public function populateFirstAndLastName(string $name): void + { + list($this->firstName, $this->lastName) = explode(' ', $name); + } } For additional information on using `#[AlsoLoad]`_, see @@ -159,16 +165,15 @@ Optional attributes: 'desc'], options: ['unique' => true]) + ], + readOnly: true, + )] class User { //... @@ -210,16 +215,19 @@ Optional attributes: Documents\BookTag::class, - 'song' => Documents\SongTag::class, - ], - defaultDiscriminatorValue: 'book', - )] - private $tags = []; + class User + { + #[EmbedMany( + strategy:'set', + discriminatorField:'type', + discriminatorMap: [ + 'book' => Documents\BookTag::class, + 'song' => Documents\SongTag::class, + ], + defaultDiscriminatorValue: 'book', + )] + private $tags = []; + } Depending on the embedded document's class, a value of ``user`` or ``author`` will be stored in the ``type`` field and used to reconstruct the proper class @@ -263,15 +271,18 @@ Optional attributes: Documents\User::class, - 'author' => Documents\Author::class, - ], - defaultDiscriminatorValue: 'user', - ) - private $creator; + class Thing + { + #[EmbedOne( + discriminatorField: 'type', + discriminatorMap: [ + 'user' => Documents\User::class, + 'author' => Documents\Author::class, + ], + defaultDiscriminatorValue: 'user', + )] + private $creator; + } Depending on the embedded document's class, a value of ``user`` or ``author`` will be stored in the ``type`` field and used to reconstruct the proper class @@ -292,7 +303,7 @@ relationship. #[EmbeddedDocument] class Money { - #[Field(type: float')] + #[Field(type: 'float')] private $amount; public function __construct(float $amount) @@ -359,14 +370,18 @@ Examples: 'desc'], options => ['unique' => true]), + new Index(keys: ['username' => 'desc'], options: ['unique' => true]), ])] class User { @@ -607,9 +626,13 @@ This is only compatible with the ``int`` type, and cannot be combined with `#[Id 'asc'] - discriminatorField: 'type', - discriminatorMap: [ - 'book' => Documents\BookItem::class, - 'song' => Documents\SongItem::class - ], - defaultDiscriminatorValue: 'book', - ) - private $cart; + class User + { + #[ReferenceMany( + strategy: 'set', + targetDocument: Documents\Item::class, + cascade: 'all', + sort: ['sort_field' => 'asc'], + discriminatorField: 'type', + discriminatorMap: [ + 'book' => Documents\BookItem::class, + 'song' => Documents\SongItem::class, + ], + defaultDiscriminatorValue: 'book', + )] + private $cart; + } .. _attributes_reference_reference_one: @@ -1023,17 +1049,20 @@ Optional attributes: Documents\BookItem::class, - 'song' => Documents\SongItem::class, - ], - defaultDiscriminatorValue: 'book' - ) - private $cart; + class User + { + #[ReferenceOne( + targetDocument: Documents\Item::class, + cascade: 'all', + discriminatorField: 'type', + discriminatorMap: [ + 'book' => Documents\BookItem::class, + 'song' => Documents\SongItem::class, + ], + defaultDiscriminatorValue: 'book' + )] + private $cart; + } #[SearchIndex] -------------- @@ -1115,9 +1144,12 @@ Alias of `#[Index]`_, with the ``unique`` option set by default. ` and :ref:`reference-many ` collections in separate write operations, diff --git a/docs/en/reference/basic-mapping.rst b/docs/en/reference/basic-mapping.rst index fc10f9c31..8edc1955d 100644 --- a/docs/en/reference/basic-mapping.rst +++ b/docs/en/reference/basic-mapping.rst @@ -342,7 +342,7 @@ as an option for the ``CUSTOM`` strategy: #[Document] class MyPersistentClass { - #[Id(strategy: 'CUSTOM', type: 'string', options: ['class' => 'Vendor\\Specific\\Generator'])] + #[Id(strategy: 'CUSTOM', type: 'string', options: ['class' => \Vendor\Specific\Generator::class])] private $id; public function setId(string $id): void @@ -445,7 +445,6 @@ the collection. Here is an example: #[Document(collection: 'my_documents')] #[DiscriminatorField('type')] #[DiscriminatorMap(['article' => Article::class, 'album' => Album::class])] - */ class Article { // ... diff --git a/docs/en/reference/complex-references.rst b/docs/en/reference/complex-references.rst index f0cdd0edb..cd18580aa 100644 --- a/docs/en/reference/complex-references.rst +++ b/docs/en/reference/complex-references.rst @@ -43,7 +43,7 @@ querying by the BlogPost's ID. mappedBy: 'blogPost', sort: ['date' => 'desc'], limit: 5, - ) + )] private $last5Comments; } @@ -63,12 +63,15 @@ following example: 'desc'] - ) - private $lastComment; + class BlogPost + { + #[ReferenceOne( + targetDocument: Comment::class, + mappedBy: 'blogPost', + sort: ['date' => 'desc'] + )] + private $lastComment; + } ``criteria`` Example -------------------- @@ -81,12 +84,15 @@ administrators: true] - )] - private $commentsByAdmin; + class BlogPost + { + #[ReferenceMany( + targetDocument: Comment::class, + mappedBy: 'blogPost', + criteria: ['isByAdmin' => true] + )] + private $commentsByAdmin; + } ``repositoryMethod`` Example ---------------------------- @@ -98,12 +104,15 @@ call on the Comment repository class to populate the reference. createQueryBuilder() - ->field('blogPost')->references($blogPost); + ->field('blogPost')->references($blogPost) ->getQuery()->execute(); } } diff --git a/docs/en/reference/custom-collections.rst b/docs/en/reference/custom-collections.rst index f00b7b96b..29e2db869 100644 --- a/docs/en/reference/custom-collections.rst +++ b/docs/en/reference/custom-collections.rst @@ -62,8 +62,8 @@ and ensuring that your custom class is initialized in the owning class' construc // ... #[EmbedMany( - collectionClass: SectionCollection::class - targetDocument: Section::class + collectionClass: SectionCollection::class, + targetDocument: Section::class, )] private $sections; diff --git a/docs/en/reference/events.rst b/docs/en/reference/events.rst index b82693d19..3a913146e 100644 --- a/docs/en/reference/events.rst +++ b/docs/en/reference/events.rst @@ -356,18 +356,21 @@ transaction and will see data that has not been committed yet. isInTransaction()) { - // Do something - } + public function someEventListener(\Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs): void + { + // To check if a transaction is active: + if ($eventArgs->isInTransaction()) { + // Do something + } - // Pass the session to any query you execute - $eventArgs->getDocumentManager()->createQueryBuilder(User::class) - // Query logic - ->getQuery(['session' => $eventArgs->session]) - ->execute(); + // Pass the session to any query you execute + $eventArgs->getDocumentManager()->createQueryBuilder(User::class) + // Query logic + ->getQuery(['session' => $eventArgs->session]) + ->execute(); + } } .. note:: diff --git a/docs/en/reference/indexes.rst b/docs/en/reference/indexes.rst index 07b300f9d..260833f0f 100644 --- a/docs/en/reference/indexes.rst +++ b/docs/en/reference/indexes.rst @@ -83,7 +83,7 @@ Unique Index public $id; #[Field(type: 'string')] - #[Index(unique:true, order: 'asc')] + #[Index(unique: true, order: 'asc')] public $username; } diff --git a/docs/en/reference/introduction.rst b/docs/en/reference/introduction.rst index 5a36ae278..e3ac57692 100644 --- a/docs/en/reference/introduction.rst +++ b/docs/en/reference/introduction.rst @@ -431,7 +431,7 @@ more paths) and register the attributes for the driver: $config->setMetadataDriverImpl(AttributeDriver::create(__DIR__ . '/Documents')); - require_once __DIR__ . '/vendor/autoload.php'); + require_once __DIR__ . '/vendor/autoload.php'; At this point, we have everything necessary to construct a ``DocumentManager``: diff --git a/docs/en/reference/reference-mapping.rst b/docs/en/reference/reference-mapping.rst index 1862cdf0b..6c2a3a7b7 100644 --- a/docs/en/reference/reference-mapping.rst +++ b/docs/en/reference/reference-mapping.rst @@ -321,9 +321,7 @@ referenced documents. You must explicitly enable this functionality: downloadToStream($file->getId(), $stream); - finally { + } finally { fclose($stream); } @@ -246,7 +246,7 @@ a stream from where you can read file contents: $stream = $repository->openDownloadStream($file->getId()); try { $contents = stream_get_contents($stream); - finally { + } finally { fclose($stream); } diff --git a/docs/en/reference/working-with-objects.rst b/docs/en/reference/working-with-objects.rst index 7bf19ef68..03624c0ae 100644 --- a/docs/en/reference/working-with-objects.rst +++ b/docs/en/reference/working-with-objects.rst @@ -521,7 +521,7 @@ simple example: // All users with an age between 20 and 30 (inclusive). $qb = $dm->createQueryBuilder(User::class) ->field('age')->range(20, 30); - $q = $qb->getQuery() + $q = $qb->getQuery(); $users = $q->execute(); By Reference