Skip to content

Commit e762952

Browse files
committed
Migrate documentation to attributes
1 parent 7ce9a6f commit e762952

File tree

2 files changed

+37
-40
lines changed

2 files changed

+37
-40
lines changed

docs/en/reference/working-with-associations.rst

+27-25
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,64 @@ information about its type and if it's the owning or inverse side.
3232
.. code-block:: php
3333
3434
<?php
35-
/** @Entity */
35+
#[Entity]
3636
class User
3737
{
38-
/** @Id @GeneratedValue @Column(type="string") */
39-
private $id;
38+
#[Id, GeneratedValue, Column(type: 'integer')]
39+
private int|null $id;
4040
4141
/**
4242
* Bidirectional - Many users have Many favorite comments (OWNING SIDE)
4343
*
44-
* @ManyToMany(targetEntity="Comment", inversedBy="userFavorites")
45-
* @JoinTable(name="user_favorite_comments")
44+
* @var Collection<int, Comment>
4645
*/
47-
private $favorites;
46+
#[ManyToMany(targetEntity: Comment::class, inversedBy: 'userFavorites')]
47+
#[JoinTable(name: 'user_favorite_comments')]
48+
private Collection $favorites;
4849
4950
/**
5051
* Unidirectional - Many users have marked many comments as read
5152
*
52-
* @ManyToMany(targetEntity="Comment")
53-
* @JoinTable(name="user_read_comments")
53+
* @var Collection<int, Comment>
5454
*/
55-
private $commentsRead;
55+
#[ManyToMany(targetEntity: Comment::class)]
56+
#[JoinTable(name: 'user_read_comments')]
57+
private Collection $commentsRead;
5658
5759
/**
5860
* Bidirectional - One-To-Many (INVERSE SIDE)
5961
*
60-
* @OneToMany(targetEntity="Comment", mappedBy="author")
62+
* @var Collection<int, Comment>
6163
*/
62-
private $commentsAuthored;
64+
#[OneToMany(targetEntity: Comment::class, mappedBy: 'author')]
65+
private Collection $commentsAuthored;
6366
64-
/**
65-
* Unidirectional - Many-To-One
66-
*
67-
* @ManyToOne(targetEntity="Comment")
68-
*/
69-
private $firstComment;
67+
/** Unidirectional - Many-To-One */
68+
#[ManyToOne(targetEntity: Comment::class)]
69+
private Comment|null $firstComment;
7070
}
7171
72-
/** @Entity */
72+
#[Entity]
7373
class Comment
7474
{
75-
/** @Id @GeneratedValue @Column(type="string") */
76-
private $id;
75+
#[Id]
76+
#[GeneratedValue]
77+
#[Column(type: 'string')]
78+
private string $id;
7779
7880
/**
7981
* Bidirectional - Many comments are favorited by many users (INVERSE SIDE)
8082
*
81-
* @ManyToMany(targetEntity="User", mappedBy="favorites")
83+
* @var Collection<int, User>
8284
*/
83-
private $userFavorites;
85+
#[ManyToMany(targetEntity: User::class, mappedBy: 'favorites')]
86+
private Collection $userFavorites;
8487
8588
/**
8689
* Bidirectional - Many Comments are authored by one user (OWNING SIDE)
87-
*
88-
* @ManyToOne(targetEntity="User", inversedBy="commentsAuthored")
8990
*/
90-
private $author;
91+
#[ManyToOne(targetEntity: User::class, inversedBy: 'commentsAuthored')]
92+
private User|null $author;
9193
}
9294
9395
This two entities generate the following MySQL Schema (Foreign Key

docs/en/tutorials/composite-primary-keys.rst

+10-15
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,28 @@ and year of production as primary keys:
2323

2424
.. configuration-block::
2525

26-
.. code-block:: php
26+
.. code-block:: attribute
2727
2828
<?php
2929
namespace VehicleCatalogue\Model;
3030
31-
/**
32-
* @Entity
33-
*/
31+
#[Entity]
3432
class Car
3533
{
36-
/** @Id @Column(type="string") */
37-
private $name;
38-
/** @Id @Column(type="integer") */
39-
private $year;
40-
41-
public function __construct($name, $year)
42-
{
43-
$this->name = $name;
44-
$this->year = $year;
34+
public function __construct(
35+
#[Id, Column(type="string")]
36+
string $name,
37+
#[Id, Column(type="integer")]
38+
int $year,
39+
) {
4540
}
4641
47-
public function getModelName()
42+
public function getModelName(): string
4843
{
4944
return $this->name;
5045
}
5146
52-
public function getYearOfProduction()
47+
public function getYearOfProduction(): int
5348
{
5449
return $this->year;
5550
}

0 commit comments

Comments
 (0)