Skip to content

Commit 0bc822a

Browse files
docs: update php type and replace annotations with PHP attributes (#1468)
* Replace ORM annotations to PHP attributes * Replace @Orm annotations to PHP attributes * Add #[ORM\Entity] * Correction of #[ORM] attribute * Modification of @Orm\Column to #[ORM\Column] for $email property * Modification of @Assert annotation to #[Assert] attribute * Corrections of PR #1466 * Docs: update PHP types for property + update old annotations with PHP attributes * Correction of typo : insersedBy to inversedBy * Delete unnecessary parenthesis * Remove type float * Modify targetEntity value * Add Question type * Add Answer type * Delete PHPDoc without @var type * Replace PHP attributes outside annotations * Add string type to $content * Remove targetEntity, mappedBy and inversedBy for OneToOne relation * Remove type DateTimeInterface due to validation test Co-authored-by: Antoine Bluchet <[email protected]>
1 parent f1aea51 commit 0bc822a

20 files changed

+205
-465
lines changed

admin/handling-relations.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ use Doctrine\ORM\Mapping as ORM;
158158
#[ApiResource]
159159
class Review
160160
{
161-
#[ORM\Id]
162-
#[ORM\GeneratedValue]
163-
#[ORM\Column(type: 'integer')]
161+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
164162
public ?int $id = null;
165163

166164
#[ORM\ManyToOne]
@@ -185,17 +183,15 @@ use Doctrine\ORM\Mapping as ORM;
185183
#[ApiResource]
186184
class Book
187185
{
188-
#[ORM\Id]
189-
#[ORM\GeneratedValue]
190-
#[ORM\Column(type: 'integer')]
186+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
191187
public ?int $id = null;
192188

193-
#[ORM\Column]
189+
#[ORM\Column]
194190
#[ApiFilter(SearchFilter::class, strategy: 'ipartial')]
195191
public string $title;
196192

197-
#[ORM\OneToMany(targetEntity: Review::class)]
198-
public Collection $reviews;
193+
#[ORM\OneToMany(targetEntity: Review::class, mappedBy: 'book')]
194+
public $reviews;
199195

200196
public function __construct()
201197
{

admin/performance.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ use Doctrine\ORM\Mapping as ORM;
2929
#[ApiResource]
3030
class Author
3131
{
32-
#[ORM\Id]
33-
#[ORM\GeneratedValue]
34-
#[ORM\Column(type: 'integer')]
32+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
3533
#[ApiFilter(SearchFilter::class, strategy: "exact")]
3634
public ?int $id = null;
3735

core/extensions.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ use ApiPlatform\Core\Annotation\ApiResource;
4646
#[ApiResource]
4747
class Offer
4848
{
49-
/**
50-
* @var User
51-
* @ORM\ManyToOne(targetEntity="User")
52-
*/
53-
public $user;
49+
#[ORM\ManyToOne]
50+
public User $user;
5451

5552
//...
5653
}

core/file-upload.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ use Symfony\Component\Validator\Constraints as Assert;
6464
use Vich\UploaderBundle\Mapping\Annotation as Vich;
6565
6666
/**
67-
* @ORM\Entity
6867
* @Vich\Uploadable
6968
*/
69+
#[ORM\Entity]
7070
#[ApiResource(
7171
iri: 'http://schema.org/MediaObject',
7272
normalizationContext: ['groups' => ['media_object:read']],
@@ -99,11 +99,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
9999
)]
100100
class MediaObject
101101
{
102-
/**
103-
* @ORM\Column(type="integer")
104-
* @ORM\GeneratedValue
105-
* @ORM\Id
106-
*/
102+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
107103
private ?int $id = null;
108104
109105
#[ApiProperty(iri: 'http://schema.org/contentUrl')]
@@ -116,9 +112,7 @@ class MediaObject
116112
#[Assert\NotNull(groups: ['media_object_create'])]
117113
public ?File $file = null;
118114
119-
/**
120-
* @ORM\Column(nullable=true)
121-
*/
115+
#[ORM\Column(nullable: true)]
122116
public ?string $filePath = null;
123117
124118
public function getId(): ?int
@@ -258,18 +252,14 @@ use Doctrine\ORM\Mapping as ORM;
258252
use Symfony\Component\HttpFoundation\File\File;
259253
use Vich\UploaderBundle\Mapping\Annotation as Vich;
260254

261-
/**
262-
* @ORM\Entity
263-
*/
255+
#[ORM\Entity]
264256
#[ApiResource(iri: 'http://schema.org/Book')]
265257
class Book
266258
{
267259
// ...
268260

269-
/**
270-
* @ORM\ManyToOne(targetEntity=MediaObject::class)
271-
* @ORM\JoinColumn(nullable=true)
272-
*/
261+
#[ORM\ManyToOne(targetEntity: MediaObject::class)]
262+
#[ORM\JoinColumn(nullable: true)]
273263
#[ApiProperty(iri: 'http://schema.org/image')]
274264
public ?MediaObject $image = null;
275265

@@ -361,9 +351,9 @@ use Symfony\Component\Serializer\Annotation\Groups;
361351
use Vich\UploaderBundle\Mapping\Annotation as Vich;
362352

363353
/**
364-
* @ORM\Entity
365354
* @Vich\Uploadable
366355
*/
356+
#[ORM\Entity]
367357
#[ApiResource(
368358
iri: 'http://schema.org/Book',
369359
normalizationContext: ['groups' => ['book:read']],
@@ -391,9 +381,7 @@ class Book
391381
#[Groups(['book:write'])]
392382
public ?File $file = null;
393383

394-
/**
395-
* @ORM\Column(nullable=true)
396-
*/
384+
#[ORM\Column(nullable: true)]
397385
public ?string $filePath = null;
398386

399387
// ...

core/filters.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,12 +1530,10 @@ use App\Entity\DummyCarColor;
15301530
#[ApiResource]
15311531
class DummyCar
15321532
{
1533-
#[ORM\Id]
1534-
#[ORM\GeneratedValue]
1535-
#[ORM\Column(type: 'integer')]
1533+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
15361534
private ?int $id = null;
15371535
1538-
#[ORM\Column(type: 'string')]
1536+
#[ORM\Column]
15391537
#[ApiFilter(SearchFilter::class, strategy: 'partial')]
15401538
public ?string $name = null;
15411539

core/fosuser-bundle.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,29 @@ use FOS\UserBundle\Model\User as BaseUser;
6363
use FOS\UserBundle\Model\UserInterface;
6464
use Symfony\Component\Serializer\Annotation\Groups;
6565
66-
/**
67-
* @ORM\Entity
68-
* @ORM\Table(name="fos_user")
69-
*/
66+
#[ORM\Entity]
67+
#[ORM\Table(name: 'fos_user')]
7068
#[ApiResource(
7169
normalizationContext: ["groups" => ["user", "user:read"]],
7270
denormalizationContext: ["groups" => ["user", "user:write"]]
7371
)]
7472
class User extends BaseUser
7573
{
76-
/**
77-
* @ORM\Id
78-
* @ORM\Column(type="integer")
79-
* @ORM\GeneratedValue(strategy="AUTO")
80-
*/
81-
protected $id;
74+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
75+
protected ?int $id = null;
8276
8377
#[Groups("user")]
84-
protected $email;
78+
protected string $email;
8579
86-
/**
87-
* @ORM\Column(type="string", length=255, nullable=true)
88-
*/
80+
#[ORM\Column(nullable: true)]
8981
#[Groups("user")]
90-
protected $fullname;
82+
protected string $fullname;
9183
9284
#[Groups("user:write")]
93-
protected $plainPassword;
85+
protected string $plainPassword;
9486
9587
#[Groups("user")]
96-
protected $username;
88+
protected string $username;
9789
9890
public function setFullname(?string $fullname): void
9991
{

core/getting-started.md

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,27 @@ use Doctrine\ORM\Mapping as ORM;
4747
use Doctrine\Common\Collections\ArrayCollection;
4848
use Symfony\Component\Validator\Constraints as Assert;
4949

50-
/**
51-
* @ORM\Entity
52-
*/
50+
#[ORM\Entity]
5351
#[ApiResource]
5452
class Product // The class name will be used to name exposed resources
5553
{
56-
/**
57-
* @ORM\Id
58-
* @ORM\GeneratedValue(strategy="AUTO")
59-
* @ORM\Column(type="integer")
60-
*/
54+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
6155
private ?int $id = null;
6256

6357
/**
6458
* A name property - this description will be available in the API documentation too.
6559
*
66-
* @ORM\Column
6760
*/
61+
#[ORM\Column]
6862
#[Assert\NotBlank]
6963
public string $name = '';
7064

7165
// Notice the "cascade" option below, this is mandatory if you want Doctrine to automatically persist the related entity
7266
/**
7367
* @var Offer[]|ArrayCollection
7468
*
75-
* @ORM\OneToMany(targetEntity="Offer", mappedBy="product", cascade={"persist"})
7669
*/
70+
#[ORM\OneToMany(targetEntity: Offer::class, mappedBy: 'product', cascade: ['persist'])]
7771
public iterable $offers;
7872

7973
public function __construct()
@@ -117,32 +111,22 @@ use Symfony\Component\Validator\Constraints as Assert;
117111
/**
118112
* An offer from my shop - this description will be automatically extracted from the PHPDoc to document the API.
119113
*
120-
* @ORM\Entity
121114
*/
115+
#[ORM\Entity]
122116
#[ApiResource(iri: 'http://schema.org/Offer')]
123117
class Offer
124118
{
125-
/**
126-
* @ORM\Column(type="integer")
127-
* @ORM\Id
128-
* @ORM\GeneratedValue(strategy="AUTO")
129-
*/
119+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
130120
private ?int $id = null;
131121

132-
/**
133-
* @ORM\Column(type="text")
134-
*/
122+
#[ORM\Column(type: 'text')]
135123
public string $description = '';
136124

137-
/**
138-
* @ORM\Column(type="float")
139-
*/
125+
#[ORM\Column]
140126
#[Assert\Range(minMessage: 'The price must be superior to 0.', min: 0)]
141127
public float $price = -1.0;
142128

143-
/**
144-
* @ORM\ManyToOne(targetEntity="Product", inversedBy="offers")
145-
*/
129+
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'offers')]
146130
public ?Product $product = null;
147131

148132
public function getId(): ?int

core/graphql.md

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,9 +1451,7 @@ class Book
14511451
14521452
public $name;
14531453
1454-
/**
1455-
* @ORM\OneToMany(targetEntity="Book")
1456-
*/
1454+
#[ORM\OneToMany(targetEntity: Book::class)]
14571455
public $relatedBooks;
14581456
14591457
// ...
@@ -1771,9 +1769,9 @@ use Symfony\Component\Validator\Constraints as Assert;
17711769
use Vich\UploaderBundle\Mapping\Annotation as Vich;
17721770
17731771
/**
1774-
* @ORM\Entity
17751772
* @Vich\Uploadable
17761773
*/
1774+
#[ORM\Entity]
17771775
#[ApiResource(
17781776
iri: 'http://schema.org/MediaObject',
17791777
normalizationContext: [
@@ -1791,37 +1789,21 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
17911789
)]
17921790
class MediaObject
17931791
{
1794-
/**
1795-
* @var int|null
1796-
*
1797-
* @ORM\Column(type="integer")
1798-
* @ORM\GeneratedValue
1799-
* @ORM\Id
1800-
*/
1801-
protected $id;
1792+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
1793+
protected ?int $id = null;
18021794
1803-
/**
1804-
* @var string|null
1805-
*
1806-
* @Groups({"media_object_read"})
1807-
*/
18081795
#[ApiProperty(iri: 'http://schema.org/contentUrl')]
1809-
public $contentUrl;
1796+
#[Groups(['media_object_read'])]
1797+
public ?string $contentUrl = null;
18101798
18111799
/**
1812-
* @var File|null
1813-
*
1814-
* @Assert\NotNull(groups={"media_object_create"})
18151800
* @Vich\UploadableField(mapping="media_object", fileNameProperty="filePath")
18161801
*/
1817-
public $file;
1802+
#[Assert\NotNull(groups: ['media_object_create'])]
1803+
public ?File $file = null;
18181804
1819-
/**
1820-
* @var string|null
1821-
*
1822-
* @ORM\Column(nullable=true)
1823-
*/
1824-
public $filePath;
1805+
#[ORM\Column(nullable: true)]
1806+
public ?string $filePath = null;
18251807
18261808
public function getId(): ?int
18271809
{

core/identifiers.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,26 +155,18 @@ use ApiPlatform\Core\Annotation\ApiProperty;
155155
use App\Uuid;
156156
use Doctrine\ORM\Mapping as ORM;
157157

158-
/**
159-
* @ORM\Entity
160-
*/
158+
#[ORM\Entity]
161159
#[ApiResource]
162160
final class Person
163161
{
164-
/**
165-
* @var int
166-
*
167-
* @ORM\Id()
168-
* @ORM\GeneratedValue()
169-
* @ORM\Column(type="integer")
170-
*/
162+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
171163
#[ApiProperty(identifier: false)]
172-
private $id;
164+
private ?int $id = null;
173165

174166
/**
175167
* @var Uuid
176-
* @ORM\Column(type="uuid", unique=true)
177168
*/
169+
#[ORM\Column(type: 'uuid', unique: true)]
178170
#[ApiProperty(identifier: true)]
179171
public $code;
180172

core/json-schema.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ use Doctrine\ORM\Mapping as ORM;
4949
#[ApiResource]
5050
class Greeting
5151
{
52-
#[ORM\Id]
53-
#[ORM\GeneratedValue]
54-
#[ORM\Column(type: "integer")]
52+
#[ORM\Id, ORM\Column, ORM\GeneratedValue]
5553
private ?int $id = null;
5654

5755
// [...]

0 commit comments

Comments
 (0)