Skip to content

Commit 123ab7d

Browse files
authored
Replace "attribute" with "argument" to avoid confusion with PHP attributes (#2741)
1 parent 5b49a51 commit 123ab7d

5 files changed

+70
-35
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ change values in the document, in this example we'll assume that the data will
7575
not change.
7676

7777
Now we can mark the document as a time series document. To do so, we use the
78-
``TimeSeries`` attribute, configuring appropriate values for the time and
78+
``#[TimeSeries]`` attribute, configuring appropriate values for the time and
7979
metadata field, which in our case stores the ID of the sensor reporting the
8080
measurement:
8181

docs/en/reference/attributes-reference.rst

+14-14
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ during hydration to select the instantiation class.
108108
.. note::
109109

110110
For backwards compatibility, the discriminator field may also be specified
111-
via either the ``name`` or ``fieldName`` attribute.
111+
via either the ``name`` or ``fieldName`` argument.
112112

113113
#[DiscriminatorMap]
114114
-------------------
@@ -141,7 +141,7 @@ and it does not contain the class name of the persisted document, a
141141
Required attribute to mark a PHP class as a document, whose persistence will be
142142
managed by ODM.
143143

144-
Optional attributes:
144+
Optional arguments:
145145

146146
-
147147
``db`` - By default, the document manager will use the MongoDB database
@@ -185,7 +185,7 @@ Optional attributes:
185185
This attribute is similar to `#[EmbedOne]`_, but instead of embedding one
186186
document, it embeds a collection of documents.
187187

188-
Optional attributes:
188+
Optional arguments:
189189

190190
-
191191
``targetDocument`` - A |FQCN| of the target document.
@@ -251,7 +251,7 @@ following excerpt from the MongoDB documentation:
251251
are eliminated. So in general, the question to ask is, "why would I not want
252252
to embed this object?"
253253

254-
Optional attributes:
254+
Optional arguments:
255255

256256
-
257257
``targetDocument`` - A |FQCN| of the target document. When typed properties
@@ -343,7 +343,7 @@ Marks an annotated instance variable for persistence. Values for this field will
343343
be saved to and loaded from the document store as part of the document class'
344344
lifecycle.
345345

346-
Optional attributes:
346+
Optional arguments:
347347

348348
-
349349
``type`` - Name of the ODM type, which will determine the value's
@@ -392,7 +392,7 @@ Examples:
392392
This marks the document as a GridFS file. GridFS allow storing larger amounts of
393393
data than regular documents.
394394

395-
Optional attributes:
395+
Optional arguments:
396396

397397
-
398398
``db`` - By default, the document manager will use the MongoDB database
@@ -445,7 +445,7 @@ This maps the ``metadata`` property of a GridFS file to a property. Metadata can
445445
be used to store additional properties in a file. The metadata document must be
446446
an embedded document mapped using `#[EmbeddedDocument]`_.
447447

448-
Optional attributes:
448+
Optional arguments:
449449

450450
-
451451
``targetDocument`` - A |FQCN| of the target document.
@@ -520,7 +520,7 @@ collection (or embedding document's collection in the case of
520520
`#[EmbeddedDocument]`_). It may also be used at the property-level to define
521521
single-field indexes.
522522

523-
Optional attributes:
523+
Optional arguments:
524524

525525
-
526526
``keys`` - Mapping of indexed fields to their ordering or index type. ODM
@@ -925,7 +925,7 @@ that will be applied when querying for the annotated document.
925925
Defines that the annotated instance variable holds a collection of referenced
926926
documents.
927927

928-
Optional attributes:
928+
Optional arguments:
929929

930930
-
931931
``targetDocument`` - A |FQCN| of the target document. A ``targetDocument``
@@ -1010,7 +1010,7 @@ Optional attributes:
10101010

10111011
Defines an instance variable holds a related document instance.
10121012

1013-
Optional attributes:
1013+
Optional arguments:
10141014

10151015
-
10161016
``targetDocument`` - A |FQCN| of the target document. A ``targetDocument``
@@ -1079,12 +1079,12 @@ Optional attributes:
10791079
This attribute is used to specify :ref:`search indexes <search_indexes>` for
10801080
`MongoDB Atlas Search <https://www.mongodb.com/docs/atlas/atlas-search/>`__.
10811081

1082-
The attributes correspond to arguments for
1082+
The arguments correspond to arguments for
10831083
`MongoDB\Collection::createSearchIndex() <https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-createSearchIndex/>`__.
1084-
Excluding ``name``, attributes are used to create the
1084+
Excluding ``name``, arguments are used to create the
10851085
`search index definition <https://www.mongodb.com/docs/manual/reference/command/createSearchIndexes/#search-index-definition-syntax>`__.
10861086

1087-
Optional attributes:
1087+
Optional arguments:
10881088

10891089
-
10901090
``name`` - Name of the search index to create, which must be unique to the
@@ -1353,7 +1353,7 @@ Required attributes:
13531353
``repositoryClass`` - a repository class is required. This repository must
13541354
implement the ``MongoDB\ODM\MongoDB\Repository\ViewRepository`` interface.
13551355

1356-
Optional attributes:
1356+
Optional arguments:
13571357

13581358
-
13591359
``db`` - By default, the document manager will use the MongoDB database

docs/en/reference/basic-mapping.rst

+52-17
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ annotations by offering a standardized approach to metadata, eliminating
3434
the need for the separate parsing library required by annotations.
3535

3636
In this documentation we follow the `PER Coding Style <https://www.php-fig.org/per/coding-style/#12-attributes>`_
37-
for attributes. We use named arguments for attributes as they argument names
38-
or attribute classes constructors are covered by Doctrine Backward-Compatibility promise.
37+
for attributes. We use named arguments for attributes as the names of their
38+
constructor arguments are covered by Doctrine Backward-Compatibility promise.
3939

4040
.. note::
4141

@@ -109,8 +109,8 @@ option as follows:
109109
Now instances of ``Documents\User`` will be persisted into a
110110
collection named ``users`` in the database ``my_db``.
111111

112-
If you want to omit the db attribute you can configure the default db
113-
to use with the ``setDefaultDB`` method:
112+
If you want to omit the ``db`` argument you can configure the default database
113+
to use with the ``setDefaultDB()`` method:
114114

115115
.. code-block:: php
116116
@@ -195,7 +195,7 @@ _________________
195195
Doctrine will skip type autoconfiguration if settings are provided explicitly.
196196

197197
Since version 2.4 Doctrine can determine usable defaults from property types
198-
on document classes. Doctrine will map PHP types to ``type`` attribute as
198+
on document classes. Doctrine will map PHP types to ``type`` arguments as
199199
follows:
200200

201201
- ``DateTime``: ``date``
@@ -392,12 +392,9 @@ Then specify the ``class`` option for the ``CUSTOM`` strategy:
392392
Fields
393393
~~~~~~
394394

395-
To mark a property for document persistence the ``#[Field]`` docblock
396-
attribute can be used. This attribute usually requires at least 1
397-
attribute to be set, the ``type``. The ``type`` attribute specifies
398-
the Doctrine Mapping Type to use for the field. If the type is not
399-
specified, 'string' is used as the default mapping type since it is
400-
the most flexible.
395+
To mark a property to be persisted in the document, add the ``#[Field]``
396+
attribute. The name and the type of the field are inferred from the property
397+
name and type.
401398

402399
Example:
403400

@@ -417,7 +414,7 @@ Example:
417414
{
418415
// ...
419416
420-
#[Field(type: 'string')]
417+
#[Field]
421418
public string $username;
422419
}
423420
@@ -436,11 +433,9 @@ Example:
436433
437434
In that example we mapped the property ``id`` to the field ``id``
438435
using the mapping type ``id`` and the property ``name`` is mapped
439-
to the field ``name`` with the default mapping type ``string``. As
440-
you can see, by default the mongo field names are assumed to be the
441-
same as the property names. To specify a different name for the
442-
field, you can use the ``name`` attribute of the Field attribute
443-
as follows:
436+
to the field ``name`` with the default mapping type ``string``.
437+
To specify a different name for the field, you can use the ``name`` argument
438+
of the Field attribute as follows:
444439

445440
.. configuration-block::
446441

@@ -458,6 +453,46 @@ as follows:
458453
459454
<field field-name="name" name="db_name" />
460455
456+
Date Fields
457+
~~~~~~~~~~~
458+
459+
MongoDB has a specific database type to store date and time values. You should never
460+
use a string to store a date. To define a date field, use the property types
461+
``DateTime`` or ``DateTimeImmutable`` so that Doctrine maps it to a BSON date.
462+
The ``date`` and ``date_immutable`` mapping types can be used explicitly;
463+
they are required only if the property type is ``DateTimeInterface`` or not set.
464+
465+
.. configuration-block::
466+
467+
.. code-block:: php
468+
469+
<?php
470+
471+
class User
472+
{
473+
#[Field]
474+
public \DateTimeImmutable $immutableDateTime;
475+
476+
#[Field]
477+
public \DateTime $mutableDateTime;
478+
479+
#[Field(type: 'date_immutable')]
480+
public \DateTimeInterface $datetime;
481+
}
482+
483+
.. code-block:: xml
484+
485+
<field field-name="immutableDateTime" type="date_immutable" />
486+
<field field-name="mutableDateTime" name="date" />
487+
<field field-name="datetime" name="date_immutable" />
488+
489+
490+
.. note::
491+
492+
Prefer using ``DateTimeImmutable`` over ``DateTime`` to avoid issues with
493+
mutable objects. If you need to modify a date, create a new instance
494+
and assign it to the property.
495+
461496
Multiple Document Types in a Collection
462497
---------------------------------------
463498

docs/en/reference/search-indexes.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ODM supports the following search index options:
3030
``dynamic`` - Enables or disables dynamic field mapping for this index.
3131
If ``true``, the index will include all fields with
3232
`supported data types <https://www.mongodb.com/docs/atlas/atlas-search/define-field-mappings/#std-label-bson-data-chart>`__.
33-
If ``false``, the ``fields`` attribute must be specified. Defaults to ``false``.
33+
If ``false``, the ``fields`` argument must be specified. Defaults to ``false``.
3434
-
3535
``fields`` - Associative array of `field mappings <https://www.mongodb.com/docs/atlas/atlas-search/define-field-mappings/>`__
3636
that specify the fields to index (keys). Required only if dynamic mapping is disabled.
@@ -41,7 +41,7 @@ ODM supports the following search index options:
4141
-
4242
``searchAnalyzer`` - Specifies the `analyzer <https://www.mongodb.com/docs/atlas/atlas-search/analyzers/>`__
4343
to apply to query text before the text is searched. Defaults to the
44-
``analyzer`` attribute, or the `standard analyzer <https://www.mongodb.com/docs/atlas/atlas-search/analyzers/standard/>`__.
44+
``analyzer`` argument, or the `standard analyzer <https://www.mongodb.com/docs/atlas/atlas-search/analyzers/standard/>`__.
4545
if both are unspecified.
4646
-
4747
``analyzers`` - Array of `custom analyzers <https://www.mongodb.com/docs/atlas/atlas-search/analyzers/custom/>`__

docs/en/reference/storing-files-with-gridfs.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ look like this:
120120
</doctrine-mongo-mapping>
121121
122122
With XML mappings, the fields are automatically mapped to camel-cased properties.
123-
To change property names, simply override the ``fieldName`` attribute for each
123+
To change property names, simply override the ``fieldName`` argument for each
124124
field. You cannot override any other options for GridFS fields.
125125

126126
The ``ImageMetadata`` class must be an embedded document:

0 commit comments

Comments
 (0)