Skip to content

Commit 29d8212

Browse files
committed
Merge branch '2.14.x' into 2.13.x-merge-up-into-2.14.x_NNKby2Yo
2 parents 47e71e3 + 3e178fa commit 29d8212

File tree

701 files changed

+2153
-454
lines changed

Some content is hidden

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

701 files changed

+2153
-454
lines changed

.github/workflows/atlas-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ jobs:
9696
run: "vendor/bin/phpunit --group atlas"
9797
env:
9898
DOCTRINE_MONGODB_SERVER: "mongodb://127.0.0.1:27017/?directConnection=true"
99-
USE_LAZY_GHOST_OBJECTS: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}
99+
USE_LAZY_GHOST_OBJECT: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}
100+
USE_NATIVE_LAZY_OBJECT: ${{ matrix.proxy == 'native' && '1' || '0' }}

.github/workflows/coding-standards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ on:
1111
jobs:
1212
coding-standards:
1313
name: "Coding Standards"
14-
uses: "doctrine/.github/.github/workflows/coding-standards.yml@12.0.0"
14+
uses: "doctrine/.github/.github/workflows/coding-standards.yml@12.1.0"

.github/workflows/continuous-integration.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ jobs:
7777
dependencies: "highest"
7878
symfony-version: "stable"
7979
proxy: "proxy-manager"
80+
# Test with Native Lazy Objects
81+
- php-version: "8.4"
82+
mongodb-version: "8.0"
83+
driver-version: "stable"
84+
dependencies: "highest"
85+
symfony-version: "stable"
86+
proxy: "native"
8087
# Test with extension 1.21
8188
- topology: "server"
8289
php-version: "8.2"
@@ -162,5 +169,6 @@ jobs:
162169
run: "vendor/bin/phpunit --exclude-group=atlas"
163170
env:
164171
DOCTRINE_MONGODB_SERVER: ${{ steps.setup-mongodb.outputs.cluster-uri }}
165-
USE_LAZY_GHOST_OBJECTS: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}"
172+
USE_LAZY_GHOST_OBJECT: ${{ matrix.proxy == 'lazy-ghost' && '1' || '0' }}
173+
USE_NATIVE_LAZY_OBJECT: ${{ matrix.proxy == 'native' && '1' || '0' }}
166174
CRYPT_SHARED_LIB_PATH: ${{ steps.setup-mongodb.outputs.crypt-shared-lib-path }}

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ on:
1717
jobs:
1818
documentation:
1919
name: "Generate documentation"
20-
uses: "doctrine/.github/.github/workflows/documentation.yml@12.0.0"
20+
uses: "doctrine/.github/.github/workflows/documentation.yml@12.1.0"

.github/workflows/performance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
uses: "ramsey/composer-install@v3"
5757

5858
- name: "Upload composer.lock as build artifact"
59-
uses: actions/upload-artifact@v4
59+
uses: actions/upload-artifact@v5
6060
with:
6161
name: composer.lock
6262
path: composer.lock

.github/workflows/release-on-milestone-closed.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ on:
88
jobs:
99
release:
1010
name: "Git tag, release & create merge-up PR"
11-
uses: "doctrine/.github/.github/workflows/[email protected]"
11+
uses: "doctrine/.github/.github/workflows/[email protected]"
12+
with:
13+
use-next-minor-as-default-branch: true
1214
secrets:
1315
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
1416
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
uses: "ramsey/composer-install@v3"
5252

5353
- name: "Upload composer.lock as build artifact"
54-
uses: actions/upload-artifact@v4
54+
uses: actions/upload-artifact@v5
5555
with:
5656
name: "composer-lock-static-analysis-phpstan"
5757
path: composer.lock

.github/workflows/website-schema.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ on:
1818
jobs:
1919
json-validate:
2020
name: "Validate JSON schema"
21-
uses: "doctrine/.github/.github/workflows/website-schema.yml@12.0.0"
21+
uses: "doctrine/.github/.github/workflows/website-schema.yml@12.1.0"

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@
6363
"ext-bcmath": "Decimal128 type support"
6464
},
6565
"autoload": {
66-
"psr-4": { "Doctrine\\ODM\\MongoDB\\": "lib/Doctrine/ODM/MongoDB" }
66+
"psr-4": { "Doctrine\\ODM\\MongoDB\\": "src" }
6767
},
6868
"autoload-dev": {
6969
"psr-4": {
7070
"Doctrine\\ODM\\MongoDB\\Benchmark\\": "benchmark",
71-
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Doctrine/ODM/MongoDB/Tests",
71+
"Doctrine\\ODM\\MongoDB\\Tests\\": "tests/Tests",
7272
"Documentation\\": "tests/Documentation",
7373
"Documents\\": "tests/Documents",
74+
"Documents84\\": "tests/Documents84",
7475
"Stubs\\": "tests/Stubs",
75-
"TestDocuments\\" :"tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures"
76+
"TestDocuments\\" :"tests/Tests/Mapping/Driver/fixtures"
7677
}
7778
},
7879
"config": {

docs/en/reference/custom-mapping-types.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ In order to create a new mapping type you need to subclass
99
``Doctrine\ODM\MongoDB\Types\Type`` and implement/override
1010
the methods.
1111

12+
Date Example: Mapping DateTimeImmutable with Timezone
13+
-----------------------------------------------------
14+
1215
The following example defines a custom type that stores ``DateTimeInterface``
1316
instances as an embedded document containing a BSON date and accompanying
1417
timezone string. Those same embedded documents are then be translated back into
@@ -32,6 +35,7 @@ a ``DateTimeImmutable`` when the data is read from the database.
3235
// This trait provides default closureToPHP used during data hydration
3336
use ClosureToPHP;
3437
38+
/** @param array{utc: UTCDateTime, tz: string} $value */
3539
public function convertToPHPValue($value): DateTimeImmutable
3640
{
3741
if (!isset($value['utc'], $value['tz'])) {
@@ -46,6 +50,7 @@ a ``DateTimeImmutable`` when the data is read from the database.
4650
return DateTimeImmutable::createFromMutable($dateTime);
4751
}
4852
53+
/** @return array{utc: UTCDateTime, tz: string} */
4954
public function convertToDatabaseValue($value): array
5055
{
5156
if (!$value instanceof DateTimeImmutable) {
@@ -115,5 +120,85 @@ specify a unique name for the mapping type and map that to the corresponding
115120
116121
<field field-name="field" type="date_with_timezone" />
117122
123+
Custom Type Example: Mapping a Money Value Object
124+
-------------------------------------------------
125+
126+
You can create a custom mapping type for your own value objects or classes. For
127+
example, to map a ``Money`` value object using the `moneyphp/money library`_, you can
128+
implement a type that converts between this class and a BSON embedded document format.
129+
130+
This approach works for any custom class by adapting the conversion logic to your needs.
131+
132+
Example Implementation (using ``Money\Money``)::
133+
134+
.. code-block:: php
135+
136+
<?php
137+
138+
namespace App\MongoDB\Types;
139+
140+
use Doctrine\ODM\MongoDB\Types\ClosureToPHP;
141+
use Doctrine\ODM\MongoDB\Types\Type;
142+
use InvalidArgumentException;
143+
use Money\Money;
144+
use Money\Currency;
145+
146+
final class MoneyType extends Type
147+
{
148+
// This trait provides a default closureToPHP used during data hydration
149+
use ClosureToPHP;
150+
151+
public function convertToPHPValue(mixed $value): ?Money
152+
{
153+
if (null === $value) {
154+
return null;
155+
}
156+
157+
if (is_array($value) && isset($value['amount'], $value['currency'])) {
158+
return new Money($value['amount'], new Currency($value['currency']));
159+
}
160+
161+
throw new InvalidArgumentException(sprintf('Could not convert database value from "%s" to %s', get_debug_type($value), Money::class));
162+
}
163+
164+
public function convertToDatabaseValue(mixed $value): ?array
165+
{
166+
if (null === $value) {
167+
return null;
168+
}
169+
170+
if ($value instanceof Money) {
171+
return [
172+
'amount' => $value->getAmount(),
173+
'currency' => $value->getCurrency()->getCode(),
174+
];
175+
}
176+
177+
throw new InvalidArgumentException(sprintf('Could not convert database value from "%s" to array', get_debug_type($value)));
178+
}
179+
}
180+
181+
Register the type in your bootstrap code::
182+
183+
.. code-block:: php
184+
185+
Type::addType(Money::class, App\MongoDB\Types\MoneyType::class);
186+
187+
By using the |FQCN| of the value object class as the type name, the type is
188+
automatically used when encountering a property of that class. This means you
189+
can omit the ``type`` option when defining the field mapping::
190+
191+
.. code-block:: php
192+
193+
#[Field]
194+
public ?\Money\Money $price;
195+
196+
.. note::
197+
198+
This implementation of ``MoneyType`` is kept simple for illustration purposes
199+
and does not handle all edge cases, but it should give you a good starting
200+
point for implementing your own custom types.
201+
202+
.. _`moneyphp/money library`: https://github.com/moneyphp/money
118203
.. |FQCN| raw:: html
119204
<abbr title="Fully-Qualified Class Name">FQCN</abbr>

0 commit comments

Comments
 (0)