Skip to content

Commit 6dffe12

Browse files
committed
Merge branch '2.9.x' into 2.8.x-merge-up-into-2.9.x_gy9cDuHl
* 2.9.x: (24 commits) Fix typo in code example (#2670) Label PRs about GH actions with "CI" (#2632) Review basic mapping (#2668) Fix wording (#2667) Add native type to private properties and final classes (#2666) Review and add tests on `ResolveTargetDocumentListener` (#2660) Remove soft-delete-cookbook (#2657) doc: Remove wakeup and clone cookbook (#2663) Modernize generated code for Hydrators (#2665) Add tests for introduction (#2664) doc: Review mapping ORM and ODM cookbook (#2658) doc: Review cookbook on blending ORM and ODM (#2656) doc: Review and test validation cookbook (#2662) Update custom mapping example (#2654) doc: Review Simple Search Engine Cookbook (#2659) doc: Add cookbook about embedding referenced documents using $lookup (#2655) doc: Add type to properties (#2652) doc: Review custom collections and repository docs (#2653) doc: Review Getting Started (#2650) Move annotations-reference to attributes-reference (#2651) ...
2 parents 511a476 + 93b9374 commit 6dffe12

File tree

113 files changed

+5004
-3227
lines changed

Some content is hidden

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

113 files changed

+5004
-3227
lines changed

.github/dependabot.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "weekly"
7+
labels:
8+
- "CI"

.github/workflows/documentation.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Documentation"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "*.x"
7+
paths:
8+
- .github/workflows/documentation.yml
9+
- docs/**
10+
push:
11+
branches:
12+
- "*.x"
13+
paths:
14+
- .github/workflows/documentation.yml
15+
- docs/**
16+
17+
jobs:
18+
validate-with-guides:
19+
name: "Validate documentation with phpDocumentor/guides"
20+
runs-on: "ubuntu-22.04"
21+
22+
steps:
23+
- name: "Checkout code"
24+
uses: "actions/checkout@v4"
25+
26+
- name: "Install PHP"
27+
uses: "shivammathur/setup-php@v2"
28+
with:
29+
coverage: "none"
30+
php-version: "8.3"
31+
32+
- name: "Install dependencies with Composer"
33+
uses: "ramsey/composer-install@v3"
34+
with:
35+
working-directory: "docs"
36+
dependency-versions: "highest"
37+
38+
- name: "Add orphan metadata where needed"
39+
run: |
40+
printf '%s\n\n%s\n' ":orphan:" "$(cat docs/en/sidebar.rst)" > docs/en/sidebar.rst
41+
printf '%s\n\n%s\n' ":orphan:" "$(cat docs/en/reference/annotations-reference.rst)" > docs/en/reference/annotations-reference.rst
42+
43+
- name: "Run guides-cli"
44+
run: "docs/vendor/bin/guides -vvv --no-progress docs/en 2>&1 | grep -v 'No template found for rendering directive' | ( ! grep WARNING )"

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"ext-bcmath": "*",
4141
"doctrine/annotations": "^1.12 || ^2.0",
4242
"doctrine/coding-standard": "^12.0",
43+
"doctrine/orm": "^3.2",
4344
"jmikola/geojson": "^1.0",
4445
"phpbench/phpbench": "^1.0.0",
4546
"phpstan/phpstan": "~1.10.67",
@@ -63,8 +64,8 @@
6364
"psr-4": {
6465
"Doctrine\\ODM\\MongoDB\\Benchmark\\": "benchmark",
6566
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Doctrine/ODM/MongoDB/Tests",
67+
"Documentation\\": "tests/Documentation",
6668
"Documents\\": "tests/Documents",
67-
"Documents81\\": "tests/Documents81",
6869
"Stubs\\": "tests/Stubs",
6970
"TestDocuments\\" :"tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures"
7071
}

docs/composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require-dev": {
3+
"phpdocumentor/guides-cli": "^1.2"
4+
}
5+
}

docs/en/cookbook/blending-orm-and-mongodb-odm.rst

+50-63
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
Blending the ORM and MongoDB ODM
22
================================
33

4-
Since the start of the `Doctrine MongoDB Object Document Mapper`_ project people have asked how it can be integrated with the `ORM`_. This article will demonstrates how you can integrate the two transparently, maintaining a clean domain model.
4+
This article demonstrates how you can integrate the `Doctrine MongoDB ODM`_
5+
and the `ORM`_ transparently, maintaining a clean domain model. This is
6+
something that is supported indirectly by the libraries by using the events.
57

6-
This example will have a ``Product`` that is stored in MongoDB and the ``Order`` stored in a MySQL database.
8+
This example will have a ``Product`` that is stored in MongoDB and the ``Order``
9+
stored in a SQL database like MySQL, PostgreSQL or SQLite.
710

811
Define Product
912
--------------
@@ -16,35 +19,21 @@ First lets define our ``Product`` document:
1619
1720
namespace Documents;
1821
19-
/** @Document */
22+
#[Document]
2023
class Product
2124
{
22-
/** @Id */
23-
private $id;
25+
#[Id]
26+
public string $id;
2427
25-
/** @Field(type="string") */
26-
private $title;
27-
28-
public function getId(): ?string
29-
{
30-
return $this->id;
31-
}
32-
33-
public function getTitle(): ?string
34-
{
35-
return $this->title;
36-
}
37-
38-
public function setTitle(string $title): void
39-
{
40-
$this->title = $title;
41-
}
28+
#[Field(type: 'string')]
29+
public string $title;
4230
}
4331
4432
Define Entity
4533
-------------
4634

47-
Next create the ``Order`` entity that has a ``$product`` and ``$productId`` property linking it to the ``Product`` that is stored with MongoDB:
35+
Next create the ``Order`` entity that has a ``$product`` and ``$productId``
36+
property linking it to the ``Product`` that is stored with MongoDB:
4837

4938
.. code-block:: php
5039
@@ -54,27 +43,19 @@ Next create the ``Order`` entity that has a ``$product`` and ``$productId`` prop
5443
5544
use Documents\Product;
5645
57-
/**
58-
* @Entity
59-
* @Table(name="orders")
60-
*/
46+
#[Entity]
47+
#[Table(name: 'orders')]
6148
class Order
6249
{
63-
/**
64-
* @Id @Column(type="int")
65-
* @GeneratedValue(strategy="AUTO")
66-
*/
67-
private $id;
68-
69-
/**
70-
* @Column(type="string")
71-
*/
72-
private $productId;
73-
74-
/**
75-
* @var Documents\Product
76-
*/
77-
private $product;
50+
#[Id]
51+
#[Column(type: 'int')]
52+
#[GeneratedValue(strategy: 'AUTO')]
53+
public int $id;
54+
55+
#[Column(type: 'string')]
56+
private string $productId;
57+
58+
private Product $product;
7859
7960
public function getId(): ?int
8061
{
@@ -101,7 +82,10 @@ Next create the ``Order`` entity that has a ``$product`` and ``$productId`` prop
10182
Event Subscriber
10283
----------------
10384

104-
Now we need to setup an event subscriber that will set the ``$product`` property of all ``Order`` instances to a reference to the document product so it can be lazily loaded when it is accessed the first time. So first register a new event subscriber:
85+
Now we need to setup an event subscriber that will set the ``$product`` property
86+
of all ``Order`` instances to a reference to the document product so it can be
87+
lazily loaded when it is accessed the first time. So first register a new event
88+
subscriber:
10589

10690
.. code-block:: php
10791
@@ -112,15 +96,17 @@ Now we need to setup an event subscriber that will set the ``$product`` property
11296
[\Doctrine\ORM\Events::postLoad], new MyEventSubscriber($dm)
11397
);
11498
115-
or in .yaml
99+
or in YAML configuration of the Symfony container:
116100

117101
.. code-block:: yaml
118102
119103
App\Listeners\MyEventSubscriber:
120104
tags:
121-
- { name: doctrine.event_listener, connection: default, event: postLoad}
105+
- { name: doctrine.event_listener, connection: default, event: postLoad }
122106
123-
So now we need to define a class named ``MyEventSubscriber`` and pass ``DocumentManager`` as a dependency. It will have a ``postLoad()`` method that sets the product document reference:
107+
So now we need to define a class named ``MyEventSubscriber`` and pass
108+
``DocumentManager`` as a dependency. It will have a ``postLoad()`` method that
109+
sets the product document reference:
124110

125111
.. code-block:: php
126112
@@ -131,10 +117,9 @@ So now we need to define a class named ``MyEventSubscriber`` and pass ``Document
131117
132118
class MyEventSubscriber
133119
{
134-
public function __construct(DocumentManager $dm)
135-
{
136-
$this->dm = $dm;
137-
}
120+
public function __construct(
121+
private readonly DocumentManager $dm,
122+
) {}
138123
139124
public function postLoad(LifecycleEventArgs $eventArgs): void
140125
{
@@ -144,13 +129,13 @@ So now we need to define a class named ``MyEventSubscriber`` and pass ``Document
144129
return;
145130
}
146131
147-
$em = $eventArgs->getEntityManager();
148-
$productReflProp = $em->getClassMetadata(Order::class)
149-
->reflClass->getProperty('product');
150-
$productReflProp->setAccessible(true);
151-
$productReflProp->setValue(
152-
$order, $this->dm->getReference(Product::class, $order->getProductId())
153-
);
132+
$product = $this->dm->getReference(Product::class, $order->getProductId());
133+
134+
$eventArgs->getObjectManager()
135+
->getClassMetadata(Order::class)
136+
->reflClass
137+
->getProperty('product')
138+
->setValue($order, $product);
154139
}
155140
}
156141
@@ -170,7 +155,7 @@ First create a new ``Product``:
170155
<?php
171156
172157
$product = new \Documents\Product();
173-
$product->setTitle('Test Product');
158+
$product->title = 'Test Product';
174159
$dm->persist($product);
175160
$dm->flush();
176161
@@ -185,19 +170,21 @@ Now create a new ``Order`` and link it to a ``Product`` in MySQL:
185170
$em->persist($order);
186171
$em->flush();
187172
188-
Later we can retrieve the entity and lazily load the reference to the document in MongoDB:
173+
Later we can retrieve the entity and lazily load the reference to the document
174+
in MongoDB:
189175

190176
.. code-block:: php
191177
192178
<?php
193179
194-
$order = $em->find(Order::class, $order->getId());
180+
$order = $em->find(Order::class, $order->id);
195181
196182
$product = $order->getProduct();
197183
198-
echo "Order Title: " . $product->getTitle();
184+
echo "Order Title: " . $product->title;
199185
200-
If you were to print the ``$order`` you would see that we got back regular PHP objects:
186+
If you were to print the ``$order`` you would see that we got back regular PHP
187+
objects:
201188

202189
.. code-block:: php
203190
@@ -221,5 +208,5 @@ The above would output the following:
221208
)
222209
)
223210
224-
.. _Doctrine MongoDB Object Document Mapper: http://www.doctrine-project.org/projects/mongodb_odm
211+
.. _Doctrine MongoDB ODM: http://www.doctrine-project.org/projects/mongodb_odm
225212
.. _ORM: http://www.doctrine-project.org/projects/orm

docs/en/cookbook/implementing-array-access-for-domain-objects.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Implementing ArrayAccess for Domain Objects
22
===========================================
33

4-
.. sectionauthor:: Roman Borschel (roman@code-factory.org)
4+
.. sectionauthor:: Roman Borschel <roman@code-factory.org>
55

66
This recipe will show you how to implement ArrayAccess for your
77
domain objects in order to allow more uniform access, for example

docs/en/cookbook/implementing-the-notify-changetracking-policy.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Implementing the Notify ChangeTracking Policy
22
=============================================
33

4-
.. sectionauthor:: Roman Borschel (roman@code-factory.org)
4+
.. sectionauthor:: Roman Borschel <roman@code-factory.org>
55

66
The NOTIFY change-tracking policy is the most effective
77
change-tracking policy provided by Doctrine but it requires some
@@ -59,7 +59,7 @@ listeners:
5959
6060
<?php
6161
62-
// Mapping not shown, either in annotations or xml as usual
62+
// Mapping not shown, either in attributes or xml as usual
6363
class MyEntity extends DomainObject
6464
{
6565
private $data;

docs/en/cookbook/implementing-wakeup-or-clone.rst

-77
This file was deleted.

0 commit comments

Comments
 (0)