Skip to content

Commit e676197

Browse files
committed
Update docs
1 parent 93e30af commit e676197

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ Custom Type Example: Mapping a UUID Class
123123

124124
You can create a custom mapping type for your own value objects or classes. For
125125
example, to map a UUID value object using the `ramsey/uuid library`_, you can
126-
implement a type that converts between your class and the MongoDB binary format.
126+
implement a type that converts between your class and the BSON Binary UUID format.
127127

128-
This approach works for any custom class—just adapt the conversion logic to your needs.
129-
130-
Example Implementation (using Ramsey\Uuid\UuidInterface)::
128+
This approach works for any custom class by adapting the conversion logic to your needs.
131129

130+
Example Implementation (using ``Ramsey\Uuid\Uuid``)::
132131

133132
.. code-block:: php
133+
134134
<?php
135135
136136
namespace My\Project\Types;
@@ -144,6 +144,7 @@ Example Implementation (using Ramsey\Uuid\UuidInterface)::
144144
145145
final class UuidType extends Type
146146
{
147+
// This trait provides default closureToPHP used during data hydration
147148
use ClosureToPHP;
148149
149150
public function convertToPHPValue(mixed $value): ?Uuid
@@ -203,23 +204,24 @@ Example Implementation (using Ramsey\Uuid\UuidInterface)::
203204
}
204205
}
205206
206-
Usage Example::
207+
Register the type in your bootstrap code::
207208

208209
.. code-block:: php
209210
210-
#[Field(type: Uuid::class)]
211-
public Uuid $id;
211+
Type::addType(Ramsey\Uuid\Uuid::class, My\Project\Types\UuidType::class);
212212
213-
Register the type in your bootstrap code::
213+
Usage Example::
214214

215215
.. code-block:: php
216216
217-
Type::addType(Ramsey\Uuid\Uuid::class, My\Project\Types\UuidType::class);
217+
#[Field(type: Ramsey\Uuid\Uuid::class)]
218+
public Ramsey\Uuid\Uuid $id;
218219
219220
.. note::
220-
The type name should match the support class name (e.g., ``uuid`` for ``UuidType``) to enable automatic association with the field type.
221-
222-
This pattern can be adapted for any custom class—just implement the conversion logic for your value object.
221+
The type name should be the name of the value object class (e.g., ``Ramsey\Uuid\Uuid``
222+
for our custom ``UuidType``) to enable automatic transformation of the values
223+
of this class in the aggregation builder.
223224

224-
.. |FQCN| raw:: html <abbr title="Fully-Qualified Class Name">FQCN</abbr>
225225
.. _`ramsey/uuid library`: https://github.com/ramsey/uuid
226+
.. |FQCN| raw:: html
227+
<abbr title="Fully-Qualified Class Name">FQCN</abbr>

0 commit comments

Comments
 (0)