Skip to content

Commit

Permalink
Fix syntax errors in PHP code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Jun 19, 2024
1 parent 43421e9 commit 5c54a56
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 139 deletions.
3 changes: 2 additions & 1 deletion docs/en/cookbook/simple-search-engine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
2 changes: 1 addition & 1 deletion docs/en/cookbook/soft-delete-extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
}
}
Expand Down
40 changes: 23 additions & 17 deletions docs/en/reference/aggregation-stage-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,17 @@ pipeline stages. Take the following relationship for example:
<?php
/**
* @ReferenceMany(
* targetDocument=Documents\Item::class,
* cascade="all",
* storeAs="id"
* )
*/
private $items;
namespace Documents;
class Orders
{
#[ReferenceMany(
targetDocument: Item::class,
cascade: 'all',
storeAs: 'id',
)]
private $items;
}
.. code-block:: php
Expand All @@ -405,14 +408,17 @@ to be considered when looking up one-to-one relationships:
<?php
/**
* @ReferenceOne(
* targetDocument=Documents\Item::class,
* cascade="all",
* storeAs="id"
* )
*/
private $items;
namespace Documents;
class Orders
{
#[ReferenceOne(
targetDocument: Item::class,
cascade: 'all',
storeAs: 'id',
)]
private $items;
}
.. code-block:: php
Expand Down Expand Up @@ -629,7 +635,7 @@ field on all document levels and evaluates it to grant or deny access:
$builder->expr()->gte('$$level', 5),
'$$PRUNE',
'$$DESCEND'
)
);
$replaceRoot
------------
Expand Down
189 changes: 112 additions & 77 deletions docs/en/reference/attributes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ does not exist.
<?php
#[Field(type: 'string')]
#[AlsoLoad('name')]
public $fullName;
class User
{
#[Field(type: 'string')]
#[AlsoLoad('name')]
public $fullName;
}
The ``$fullName`` property will be loaded from ``fullName`` if it exists, but
fall back to ``name`` if it does not exist. If multiple fall back fields are
Expand All @@ -30,10 +33,13 @@ will be invoked with the first value found as its single argument.
<?php
#[AlsoLoad({"name", "fullName"})]
public function populateFirstAndLastName(string $name): void
class User
{
list($this->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
Expand Down Expand Up @@ -159,16 +165,15 @@ Optional attributes:
<?php
#[Document(]
#[Document(
db: 'documents',
collection: 'users',
repositoryClass :'MyProject\UserRepository',
indexes: {
new Index(keys: ['username'='desc'}, options={'unique'=true})
},
readOnly=true,
* )
*/
repositoryClass: MyProject\UserRepository::class,
indexes: [
new Index(keys: ['username' => 'desc'], options: ['unique' => true])
],
readOnly: true,
)]
class User
{
//...
Expand Down Expand Up @@ -210,16 +215,19 @@ Optional attributes:
<?php
#[EmbedMany(
strategy:'set',
discriminatorField:'type',
discriminatorMap: [
'book' => 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
Expand Down Expand Up @@ -263,15 +271,18 @@ Optional attributes:
<?php
#[EmbedOne(
discriminatorField: 'type',
discriminatorMap: [
'user' => 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
Expand All @@ -292,7 +303,7 @@ relationship.
#[EmbeddedDocument]
class Money
{
#[Field(type: float')]
#[Field(type: 'float')]
private $amount;
public function __construct(float $amount)
Expand Down Expand Up @@ -359,14 +370,18 @@ Examples:
<?php
#[Field(type: 'string')]
protected $username;
#[Document]
class User
{
#[Field(type: 'string')]
protected $username;
#[Field(type: 'string', name: 'co')]
protected $country;
#[Field(type: 'string', name: 'co')]
protected $country;
#[Field(type: 'float')]
protected $height;
#[Field(type: 'float')]
protected $height;
}
.. _file:

Expand Down Expand Up @@ -531,9 +546,13 @@ If you are creating a single-field index, you can simply specify an `#[Index]`_
<?php
#[Field(type: 'string')]
#[UniqueIndex]
private $username;
#[Document]
class User
{
#[Field(type: 'string')]
#[UniqueIndex]
private $username;
}
.. note::

Expand Down Expand Up @@ -561,7 +580,7 @@ attributes on a class level.
#[Document]
#[Indexes([
new Index(keys: ['username' => 'desc'], options => ['unique' => true]),
new Index(keys: ['username' => 'desc'], options: ['unique' => true]),
])]
class User
{
Expand Down Expand Up @@ -607,9 +626,13 @@ This is only compatible with the ``int`` type, and cannot be combined with `#[Id
<?php
#[Field(type: int')]
#[Lock]
private $lock;
#[Document]
class Thing
{
#[Field(type: 'int')]
#[Lock]
private $lock;
}
#[MappedSuperclass]
-------------------
Expand Down Expand Up @@ -954,19 +977,22 @@ Optional attributes:
<?php
#[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;
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:

Expand Down Expand Up @@ -1023,17 +1049,20 @@ Optional attributes:
<?php
#[ReferenceOne(
targetDocument: Documents\Item::class,
cascade: 'all',
discriminatorField: 'type',
discriminatorMap: [
'book' => 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]
--------------
Expand Down Expand Up @@ -1115,9 +1144,12 @@ Alias of `#[Index]`_, with the ``unique`` option set by default.
<?php
#[Field(type: 'string')]
#[UniqueIndex]
private $email;
class User
{
#[Field(type: 'string')]
#[UniqueIndex]
private $email;
}
.. _attributes_reference_version:

Expand Down Expand Up @@ -1222,9 +1254,12 @@ combined with `#[Id]`_. Following ODM types can be used for versioning: ``int``,
<?php
#[Field(type: 'int')]
#[Version]
private $version;
class Thing
{
#[Field(type: 'int')]
#[Version]
private $version;
}
By default, Doctrine ODM updates :ref:`embed-many <embed_many>` and
:ref:`reference-many <reference_many>` collections in separate write operations,
Expand Down
3 changes: 1 addition & 2 deletions docs/en/reference/basic-mapping.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
// ...
Expand Down
Loading

0 comments on commit 5c54a56

Please sign in to comment.