Skip to content

Commit 8f22b8c

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: Replace ORM annotations with attributes, remove ORM annotation configuration block
2 parents 508e925 + 049833e commit 8f22b8c

File tree

11 files changed

+44
-306
lines changed

11 files changed

+44
-306
lines changed

components/uid.rst

+12-24
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,10 @@ type, which converts to/from UUID objects automatically::
133133

134134
use Doctrine\ORM\Mapping as ORM;
135135

136-
/**
137-
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
138-
*/
136+
#[ORM\Entity(repositoryClass: ProductRepository::class)]
139137
class Product
140138
{
141-
/**
142-
* @ORM\Column(type="uuid")
143-
*/
139+
#[ORM\Column(type: 'uuid')]
144140
private $someProperty;
145141

146142
// ...
@@ -156,12 +152,10 @@ entity primary keys::
156152

157153
class User implements UserInterface
158154
{
159-
/**
160-
* @ORM\Id
161-
* @ORM\Column(type="uuid", unique=true)
162-
* @ORM\GeneratedValue(strategy="CUSTOM")
163-
* @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
164-
*/
155+
#[ORM\Id]
156+
#[ORM\Column(type: 'uuid', unique: true)]
157+
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
158+
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
165159
private $id;
166160

167161
public function getId(): ?Uuid
@@ -291,14 +285,10 @@ type, which converts to/from ULID objects automatically::
291285

292286
use Doctrine\ORM\Mapping as ORM;
293287

294-
/**
295-
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
296-
*/
288+
#[ORM\Entity(repositoryClass: ProductRepository::class)]
297289
class Product
298290
{
299-
/**
300-
* @ORM\Column(type="ulid")
301-
*/
291+
#[ORM\Column(type: 'ulid')]
302292
private $someProperty;
303293

304294
// ...
@@ -314,12 +304,10 @@ entity primary keys::
314304

315305
class Product
316306
{
317-
/**
318-
* @ORM\Id
319-
* @ORM\Column(type="ulid", unique=true)
320-
* @ORM\GeneratedValue(strategy="CUSTOM")
321-
* @ORM\CustomIdGenerator(class="doctrine.ulid_generator")
322-
*/
307+
#[ORM\Id]
308+
#[ORM\Column(type: 'ulid', unique: true)]
309+
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
310+
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
323311
private $id;
324312

325313
public function getId(): ?Ulid

controller/upload_file.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ add a PDF brochure for each product. To do so, add a new property called
2424
{
2525
// ...
2626

27-
/**
28-
* @ORM\Column(type="string")
29-
*/
27+
#[ORM\Column(type: 'string')]
3028
private $brochureFilename;
3129

3230
public function getBrochureFilename()

doctrine.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ If you want to use XML instead of annotations, add ``type: xml`` and
205205
Be careful not to use reserved SQL keywords as your table or column names
206206
(e.g. ``GROUP`` or ``USER``). See Doctrine's `Reserved SQL keywords documentation`_
207207
for details on how to escape these. Or, change the table name with
208-
``#[ORM\Table(name: "groups")]`` above the class or configure the column name with
209-
the ``name: "group_name"`` option.
208+
``#[ORM\Table(name: 'groups')]`` above the class or configure the column name with
209+
the ``name: 'group_name'`` option.
210210

211211
.. _doctrine-creating-the-database-tables-schema:
212212

doctrine/associations.rst

+5-78
Original file line numberDiff line numberDiff line change
@@ -140,34 +140,6 @@ the ``Product`` entity (and getter & setter methods):
140140

141141
.. configuration-block::
142142

143-
.. code-block:: php-annotations
144-
145-
// src/Entity/Product.php
146-
namespace App\Entity;
147-
148-
// ...
149-
class Product
150-
{
151-
// ...
152-
153-
/**
154-
* @ORM\ManyToOne(targetEntity="App\Entity\Category", inversedBy="products")
155-
*/
156-
private $category;
157-
158-
public function getCategory(): ?Category
159-
{
160-
return $this->category;
161-
}
162-
163-
public function setCategory(?Category $category): self
164-
{
165-
$this->category = $category;
166-
167-
return $this;
168-
}
169-
}
170-
171143
.. code-block:: php-attributes
172144
173145
// src/Entity/Product.php
@@ -178,7 +150,7 @@ the ``Product`` entity (and getter & setter methods):
178150
{
179151
// ...
180152
181-
#[ORM\ManyToOne(targetEntity: Category::class, inversedBy: "products")]
153+
#[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'products')]
182154
private $category;
183155
184156
public function getCategory(): ?Category
@@ -237,40 +209,6 @@ class that will hold these objects:
237209

238210
.. configuration-block::
239211

240-
.. code-block:: php-annotations
241-
242-
// src/Entity/Category.php
243-
namespace App\Entity;
244-
245-
// ...
246-
use Doctrine\Common\Collections\ArrayCollection;
247-
use Doctrine\Common\Collections\Collection;
248-
249-
class Category
250-
{
251-
// ...
252-
253-
/**
254-
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category")
255-
*/
256-
private $products;
257-
258-
public function __construct()
259-
{
260-
$this->products = new ArrayCollection();
261-
}
262-
263-
/**
264-
* @return Collection|Product[]
265-
*/
266-
public function getProducts(): Collection
267-
{
268-
return $this->products;
269-
}
270-
271-
// addProduct() and removeProduct() were also added
272-
}
273-
274212
.. code-block:: php-attributes
275213
276214
// src/Entity/Category.php
@@ -284,7 +222,7 @@ class that will hold these objects:
284222
{
285223
// ...
286224
287-
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: "category")]
225+
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'category')]
288226
private $products;
289227
290228
public function __construct()
@@ -647,24 +585,13 @@ that behavior, use the `orphanRemoval`_ option inside ``Category``:
647585

648586
.. configuration-block::
649587

650-
.. code-block:: php-annotations
651-
652-
// src/Entity/Category.php
653-
654-
// ...
655-
656-
/**
657-
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="category", orphanRemoval=true)
658-
*/
659-
private $products;
660-
661588
.. code-block:: php-attributes
662589
663590
// src/Entity/Category.php
664591
665592
// ...
666593
667-
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: "category", orphanRemoval: true)]
594+
#[ORM\OneToMany(targetEntity: Product::class, mappedBy: 'category', orphanRemoval: true)]
668595
private $products;
669596
670597
@@ -681,8 +608,8 @@ Doctrine's `Association Mapping Documentation`_.
681608

682609
.. note::
683610

684-
If you're using annotations, you'll need to prepend all annotations with
685-
``@ORM\`` (e.g. ``@ORM\OneToMany``), which is not reflected in Doctrine's
611+
If you're using attributes, you'll need to prepend all attributes with
612+
``#[ORM\]`` (e.g. ``#[ORM\OneToMany]``), which is not reflected in Doctrine's
686613
documentation.
687614

688615
.. _`Association Mapping Documentation`: https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/association-mapping.html

doctrine/events.rst

-27
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,6 @@ define a callback for the ``prePersist`` Doctrine event:
5353

5454
.. configuration-block::
5555

56-
.. code-block:: php-annotations
57-
58-
// src/Entity/Product.php
59-
namespace App\Entity;
60-
61-
use Doctrine\ORM\Mapping as ORM;
62-
63-
// When using annotations, don't forget to add @ORM\HasLifecycleCallbacks()
64-
// to the class of the entity where you define the callback
65-
66-
/**
67-
* @ORM\Entity()
68-
* @ORM\HasLifecycleCallbacks()
69-
*/
70-
class Product
71-
{
72-
// ...
73-
74-
/**
75-
* @ORM\PrePersist
76-
*/
77-
public function setCreatedAtValue(): void
78-
{
79-
$this->createdAt = new \DateTimeImmutable();
80-
}
81-
}
82-
8356
.. code-block:: php-attributes
8457
8558
// src/Entity/Product.php

doctrine/resolve_target_entity.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ A Customer entity::
4646
use App\Model\InvoiceSubjectInterface;
4747
use Doctrine\ORM\Mapping as ORM;
4848

49-
/**
50-
* @ORM\Entity
51-
* @ORM\Table(name="customer")
52-
*/
49+
#[ORM\Entity]
50+
#[ORM\Table(name: 'customer')]
5351
class Customer extends BaseCustomer implements InvoiceSubjectInterface
5452
{
5553
// In this example, any methods defined in the InvoiceSubjectInterface
@@ -66,16 +64,15 @@ An Invoice entity::
6664

6765
/**
6866
* Represents an Invoice.
69-
*
70-
* @ORM\Entity
71-
* @ORM\Table(name="invoice")
7267
*/
68+
#[ORM\Entity]
69+
#[ORM\Table(name: 'invoice')]
7370
class Invoice
7471
{
7572
/**
76-
* @ORM\ManyToOne(targetEntity="App\Model\InvoiceSubjectInterface")
7773
* @var InvoiceSubjectInterface
7874
*/
75+
#[ORM\ManyToOne(targetEntity: InvoiceSubjectInterface::class)]
7976
protected $subject;
8077
}
8178

form/form_collections.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,13 @@ you will learn about next!).
407407

408408
.. configuration-block::
409409

410-
.. code-block:: php-annotations
410+
.. code-block:: php-attributes
411411
412412
// src/Entity/Task.php
413413
414414
// ...
415415
416-
/**
417-
* @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"})
418-
*/
416+
#[ORM\ManyToMany(targetEntity: Tag::class, cascade: ['persist'])]
419417
protected $tags;
420418
421419
.. code-block:: yaml

quick_tour/flex_recipes.rst

+8-16
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Security components, as well as the Doctrine ORM. In fact, Flex installed *5* re
186186

187187
But like usual, we can immediately start using the new library. Want to create a
188188
rich API for a ``product`` table? Create a ``Product`` entity and give it the
189-
``@ApiResource()`` annotation::
189+
``#[ApiResource]`` attribute::
190190

191191
<?php
192192
// src/Entity/Product.php
@@ -195,27 +195,19 @@ rich API for a ``product`` table? Create a ``Product`` entity and give it the
195195
use ApiPlatform\Core\Annotation\ApiResource;
196196
use Doctrine\ORM\Mapping as ORM;
197197

198-
/**
199-
* @ORM\Entity()
200-
* @ApiResource()
201-
*/
198+
#[ORM\Entity]
199+
#[ApiResource]
202200
class Product
203201
{
204-
/**
205-
* @ORM\Id
206-
* @ORM\GeneratedValue(strategy="AUTO")
207-
* @ORM\Column(type="integer")
208-
*/
202+
#[ORM\Id]
203+
#[ORM\GeneratedValue(strategy: 'AUTO')]
204+
#[ORM\Column(type: 'integer')]
209205
private $id;
210206

211-
/**
212-
* @ORM\Column(type="string")
213-
*/
207+
#[ORM\Column(type: 'string')]
214208
private $name;
215209

216-
/**
217-
* @ORM\Column(type="int")
218-
*/
210+
#[ORM\Column(type: 'integer')]
219211
private $price;
220212

221213
// ...

0 commit comments

Comments
 (0)