Skip to content

Commit e4664b8

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

File tree

2 files changed

+41
-40
lines changed

2 files changed

+41
-40
lines changed

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

+29-25
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,66 @@ 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]
39+
#[GeneratedValue]
40+
#[Column(type: 'string')]
41+
private string $id;
4042
4143
/**
4244
* Bidirectional - Many users have Many favorite comments (OWNING SIDE)
4345
*
44-
* @ManyToMany(targetEntity="Comment", inversedBy="userFavorites")
45-
* @JoinTable(name="user_favorite_comments")
46+
* @var Collection<int, Comment>
4647
*/
47-
private $favorites;
48+
#[ManyToMany(targetEntity: Comment::class, inversedBy: 'userFavorites')]
49+
#[JoinTable(name: 'user_favorite_comments')]
50+
private Collection $favorites;
4851
4952
/**
5053
* Unidirectional - Many users have marked many comments as read
5154
*
52-
* @ManyToMany(targetEntity="Comment")
53-
* @JoinTable(name="user_read_comments")
55+
* @var Collection<int, Comment>
5456
*/
55-
private $commentsRead;
57+
#[ManyToMany(targetEntity: Comment::class)]
58+
#[JoinTable(name: 'user_read_comments')]
59+
private Collection $commentsRead;
5660
5761
/**
5862
* Bidirectional - One-To-Many (INVERSE SIDE)
5963
*
60-
* @OneToMany(targetEntity="Comment", mappedBy="author")
64+
* @var Collection<int, Comment>
6165
*/
62-
private $commentsAuthored;
66+
#[OneToMany(targetEntity: Comment::class, mappedBy: 'author')]
67+
private Collection $commentsAuthored;
6368
64-
/**
65-
* Unidirectional - Many-To-One
66-
*
67-
* @ManyToOne(targetEntity="Comment")
68-
*/
69-
private $firstComment;
69+
/** Unidirectional - Many-To-One */
70+
#[ManyToOne(targetEntity: Comment::class)]
71+
private Comment $firstComment;
7072
}
7173
72-
/** @Entity */
74+
#[Entity]
7375
class Comment
7476
{
75-
/** @Id @GeneratedValue @Column(type="string") */
76-
private $id;
77+
#[Id]
78+
#[GeneratedValue]
79+
#[Column(type: 'string')]
80+
private string $id;
7781
7882
/**
7983
* Bidirectional - Many comments are favorited by many users (INVERSE SIDE)
8084
*
81-
* @ManyToMany(targetEntity="User", mappedBy="favorites")
85+
* @var Collection<int, User>
8286
*/
83-
private $userFavorites;
87+
#[ManyToMany(targetEntity: User::class, mappedBy: 'favorites')]
88+
private Collection $userFavorites;
8489
8590
/**
8691
* Bidirectional - Many Comments are authored by one user (OWNING SIDE)
87-
*
88-
* @ManyToOne(targetEntity="User", inversedBy="commentsAuthored")
8992
*/
90-
private $author;
93+
#[ManyToOne(targetEntity: User::class, inversedBy: 'commentsAuthored')]
94+
private User $author;
9195
}
9296
9397
This two entities generate the following MySQL Schema (Foreign Key

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

+12-15
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,30 @@ 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]
36+
#[Column(type="string")]
37+
string $name,
38+
#[Id]
39+
#[Column(type="integer")]
40+
int $year,
41+
) {
4542
}
4643
47-
public function getModelName()
44+
public function getModelName(): string
4845
{
4946
return $this->name;
5047
}
5148
52-
public function getYearOfProduction()
49+
public function getYearOfProduction(): int
5350
{
5451
return $this->year;
5552
}

0 commit comments

Comments
 (0)