Skip to content

Commit e44c570

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Replace ORM annotations with attributes, remove ORM annotation configuration block
2 parents e7b5d54 + 8f22b8c commit e44c570

File tree

11 files changed

+44
-306
lines changed

11 files changed

+44
-306
lines changed

components/uid.rst

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,10 @@ type, which converts to/from UUID objects automatically::
138138

139139
use Doctrine\ORM\Mapping as ORM;
140140

141-
/**
142-
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
143-
*/
141+
#[ORM\Entity(repositoryClass: ProductRepository::class)]
144142
class Product
145143
{
146-
/**
147-
* @ORM\Column(type="uuid")
148-
*/
144+
#[ORM\Column(type: 'uuid')]
149145
private $someProperty;
150146

151147
// ...
@@ -161,12 +157,10 @@ entity primary keys::
161157

162158
class User implements UserInterface
163159
{
164-
/**
165-
* @ORM\Id
166-
* @ORM\Column(type="uuid", unique=true)
167-
* @ORM\GeneratedValue(strategy="CUSTOM")
168-
* @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
169-
*/
160+
#[ORM\Id]
161+
#[ORM\Column(type: 'uuid', unique: true)]
162+
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
163+
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
170164
private $id;
171165

172166
public function getId(): ?Uuid
@@ -301,14 +295,10 @@ type, which converts to/from ULID objects automatically::
301295

302296
use Doctrine\ORM\Mapping as ORM;
303297

304-
/**
305-
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
306-
*/
298+
#[ORM\Entity(repositoryClass: ProductRepository::class)]
307299
class Product
308300
{
309-
/**
310-
* @ORM\Column(type="ulid")
311-
*/
301+
#[ORM\Column(type: 'ulid')]
312302
private $someProperty;
313303

314304
// ...
@@ -324,12 +314,10 @@ entity primary keys::
324314

325315
class Product
326316
{
327-
/**
328-
* @ORM\Id
329-
* @ORM\Column(type="ulid", unique=true)
330-
* @ORM\GeneratedValue(strategy="CUSTOM")
331-
* @ORM\CustomIdGenerator(class="doctrine.ulid_generator")
332-
*/
317+
#[ORM\Id]
318+
#[ORM\Column(type: 'ulid', unique: true)]
319+
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
320+
#[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')]
333321
private $id;
334322

335323
public function getId(): ?Ulid

controller/upload_file.rst

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 78 deletions
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

Lines changed: 0 additions & 27 deletions
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

Lines changed: 5 additions & 8 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 8 additions & 16 deletions
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)