Skip to content

Commit fe9f98e

Browse files
authored
Update subresources.md (#1262)
1 parent b7a4db1 commit fe9f98e

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed

core/subresources.md

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use Doctrine\ORM\Mapping as ORM;
2121

2222
/**
2323
* @ORM\Entity
24-
* @ApiResource
2524
*/
25+
#[ApiResource]
2626
class Answer
2727
{
2828
/**
@@ -60,8 +60,8 @@ use Doctrine\ORM\Mapping as ORM;
6060

6161
/**
6262
* @ORM\Entity
63-
* @ApiResource
6463
*/
64+
#[ApiResource]
6565
class Question
6666
{
6767
/**
@@ -79,8 +79,8 @@ class Question
7979
/**
8080
* @ORM\OneToOne(targetEntity="Answer", inversedBy="question")
8181
* @ORM\JoinColumn(referencedColumnName="id", unique=true)
82-
* @ApiSubresource
8382
*/
83+
#[ApiSubresource]
8484
public $answer;
8585

8686
public function getId(): ?int
@@ -104,7 +104,7 @@ App\Entity\Question:
104104
```
105105
[/codeSelector]
106106
107-
Note that all we had to do is to set up `@ApiSubresource` on the `Question::answer` relation. Because the `answer` is a to-one relation, we know that this subresource is an item. Therefore the response will look like this:
107+
Note that all we had to do is to set up `#[ApiSubresource]` on the `Question::answer` relation. Because the `answer` is a to-one relation, we know that this subresource is an item. Therefore the response will look like this:
108108

109109
```json
110110
{
@@ -136,14 +136,16 @@ namespace App\Entity;
136136
137137
use ApiPlatform\Core\Annotation\ApiResource;
138138
139-
/**
140-
* @ApiResource(subresourceOperations={
141-
* "api_questions_answer_get_subresource"={
142-
* "method"="GET",
143-
* "normalization_context"={"groups"={"foobar"}}
144-
* }
145-
* })
146-
*/
139+
#[ApiResource(
140+
subresourceOperations: [
141+
'api_questions_answer_get_subresource': [
142+
'method' => 'GET',
143+
'normalization_context': [
144+
'groups': ['foobar'],
145+
],
146+
],
147+
],
148+
)]
147149
class Answer
148150
{
149151
// ...
@@ -198,17 +200,14 @@ You can control the path of subresources with the `path` option of the `subresou
198200
<?php
199201
// api/src/Entity/Question.php
200202
201-
/**
202-
* ...
203-
* @ApiResource(
204-
* subresourceOperations={
205-
* "api_questions_answer_get_subresource"={
206-
* "method"="GET",
207-
* "path"="/questions/{id}/all-answers"
208-
* },
209-
* },
210-
* )
211-
*/
203+
#[ApiResource(
204+
subresourceOperations: [
205+
'api_questions_answer_get_subresource': [
206+
'method' => 'GET',
207+
'path' => '/questions/{id}/all-answers',
208+
],
209+
],
210+
)]
212211
class Question
213212
{
214213
}
@@ -222,16 +221,13 @@ The `subresourceOperations` attribute also allows you to add an access control o
222221
<?php
223222
// api/src/Entity/Answer.php
224223
225-
/**
226-
* ...
227-
* @ApiResource(
228-
* subresourceOperations={
229-
* "api_questions_answer_get_subresource"= {
230-
* "security"="has_role('ROLE_AUTHENTICATED')"
231-
* }
232-
* }
233-
* )
234-
*/
224+
#[ApiResource(
225+
subresourceOperations: [
226+
'api_questions_answer_get_subresource': [
227+
'security' => "has_role('ROLE_AUTHENTICATED')",
228+
],
229+
],
230+
)]
235231
class Answer
236232
{
237233
}
@@ -250,16 +246,12 @@ use ApiPlatform\Core\Annotation\ApiProperty;
250246
use ApiPlatform\Core\Annotation\ApiResource;
251247
use ApiPlatform\Core\Annotation\ApiSubresource;
252248
253-
/**
254-
* ...
255-
* @ApiResource
256-
*/
249+
#[ApiResource]
257250
class Question
258251
{
259-
/**
260-
* ...
261-
* @ApiSubresource(maxDepth=1)
262-
*/
252+
#[ApiSubresource(
253+
maxDepth: 1,
254+
)]
263255
public $answer;
264256
265257
// ...

0 commit comments

Comments
 (0)