@@ -70,13 +70,10 @@ namespace App\Entity;
70
70
71
71
use ApiPlatform\Core\Annotation\ApiResource;
72
72
73
- /**
74
- * ...
75
- * @ApiResource(
76
- * collectionOperations={"get"},
77
- * itemOperations={"get"}
78
- * )
79
- */
73
+ #[ApiResource(
74
+ collectionOperations: ['get'],
75
+ itemOperations: ['get'],
76
+ )]
80
77
class Book
81
78
{
82
79
// ...
@@ -122,13 +119,14 @@ namespace App\Entity;
122
119
123
120
use ApiPlatform\Core\Annotation\ApiResource;
124
121
125
- /**
126
- * ...
127
- * @ApiResource(
128
- * collectionOperations={"get"={"method"="GET"}},
129
- * itemOperations={"get"={"method"="GET"}}
130
- * )
131
- */
122
+ #[ApiResource(
123
+ collectionOperations: [
124
+ 'get' => ['method' => 'get'],
125
+ ],
126
+ itemOperations: [
127
+ 'get' => ['method' => 'get'],
128
+ ],
129
+ )]
132
130
class Book
133
131
{
134
132
// ...
@@ -149,23 +147,21 @@ namespace App\Entity;
149
147
use ApiPlatform\Core\Action\NotFoundAction;
150
148
use ApiPlatform\Core\Annotation\ApiResource;
151
149
152
- /**
153
- * @ApiResource(
154
- * collectionOperations={
155
- * "get",
156
- * },
157
- * itemOperations={
158
- * "get"={
159
- * "controller"=NotFoundAction::class,
160
- * "read"=false,
161
- * "output"=false,
162
- * },
163
- * },
164
- * )
165
- */
166
- class Book
167
- {
168
- }
150
+ #[ApiResource(
151
+ collectionOperations: [
152
+ 'get' => ['method' => 'get'],
153
+ ],
154
+ itemOperations: [
155
+ 'get' => [
156
+ 'controller' => NotFoundAction::class,
157
+ 'read' => false,
158
+ 'output' => false,
159
+ ],
160
+ ],
161
+ )]
162
+ class Book
163
+ {
164
+ }
169
165
```
170
166
171
167
## Configuring Operations
@@ -184,24 +180,24 @@ namespace App\Entity;
184
180
185
181
use ApiPlatform\Core\Annotation\ApiResource;
186
182
187
- /**
188
- * ...
189
- * @ApiResource(
190
- * collectionOperations={
191
- * "post"={"path"="/grimoire", " status"= 301}
192
- * } ,
193
- * itemOperations={
194
- * "get"={
195
- * "path"="/grimoire/{id}",
196
- * "requirements"={"id"="\d+"} ,
197
- * "defaults"={"color"="brown"} ,
198
- * "options"={"my_option"="my_option_value"} ,
199
- * "schemes"={"https"} ,
200
- * "host"="{subdomain}.api-platform.com"
201
- * }
202
- * }
203
- * )
204
- */
183
+ #[ApiResource(
184
+ collectionOperations: [
185
+ 'post' => [
186
+ 'path' => '/grimoire',
187
+ ' status' => 301,
188
+ ] ,
189
+ ],
190
+ itemOperations: [
191
+ 'get' => [
192
+ 'path' => '/grimoire/{id}' ,
193
+ 'requirements' => ['id' => '\d+'] ,
194
+ 'defaults' => ['color' => 'brown'] ,
195
+ 'options' => ['my_option' => 'my_option_value'] ,
196
+ 'schemes' => ['https'],
197
+ 'host' => '{subdomain}.api-platform.com',
198
+ ],
199
+ ],
200
+ )]
205
201
class Book
206
202
{
207
203
//...
@@ -284,9 +280,7 @@ namespace App\Entity;
284
280
285
281
use ApiPlatform\Core\Annotation\ApiResource;
286
282
287
- /**
288
- * @ApiResource(routePrefix="/library")
289
- */
283
+ #[ApiResource(routePrefix: '/library')]
290
284
class Book
291
285
{
292
286
//...
@@ -340,24 +334,19 @@ use Symfony\Component\Routing\Annotation\Route;
340
334
341
335
class CreateBookPublication
342
336
{
343
- private $bookPublishingHandler;
344
-
345
- public function __construct(BookPublishingHandler $bookPublishingHandler)
346
- {
347
- $this->bookPublishingHandler = $bookPublishingHandler;
348
- }
349
-
350
- /**
351
- * @Route(
352
- * name="book_post_publication",
353
- * path="/books/{id}/publication",
354
- * methods={"POST"},
355
- * defaults={
356
- * "_api_resource_class"=Book::class,
357
- * "_api_item_operation_name"="post_publication"
358
- * }
359
- * )
360
- */
337
+ public function __construct(
338
+ private BookPublishingHandler $bookPublishingHandler
339
+ ) {}
340
+
341
+ #[Route(
342
+ path: '/books/{id}/publication',
343
+ name: 'book_post_publication',
344
+ defaults: [
345
+ '_api_resource_class' => Book::class,
346
+ '_api_item_operation_name' => 'post_publication',
347
+ ],
348
+ methods: ['POST'],
349
+ )]
361
350
public function __invoke(Book $data): Book
362
351
{
363
352
$this->bookPublishingHandler->handle($data);
@@ -424,34 +413,26 @@ use Doctrine\ORM\Mapping as ORM;
424
413
class Place
425
414
{
426
415
/**
427
- * @var int
428
- *
429
- * @ORM\Id
430
- * @ORM\GeneratedValue
431
- * @ORM\Column(type="integer")
432
- */
433
- private $id;
416
+ * @ORM\Id
417
+ * @ORM\GeneratedValue
418
+ * @ORM\Column(type="integer")
419
+ */
420
+ private ?int $id = null;
434
421
435
422
/**
436
- * @var string
437
- *
438
- * @ORM\Column
439
- */
440
- private $name;
423
+ * @ORM\Column
424
+ */
425
+ private string $name = '';
441
426
442
427
/**
443
- * @var float
444
- *
445
- * @ORM\Column(type="float")
446
- */
447
- private $latitude;
428
+ * @ORM\Column(type="float")
429
+ */
430
+ private float $latitude = 0;
448
431
449
432
/**
450
- * @var float
451
- *
452
- * @ORM\Column(type="float")
453
- */
454
- private $longitude;
433
+ * @ORM\Column(type="float")
434
+ */
435
+ private float $longitude = 0;
455
436
456
437
// ...
457
438
}
@@ -465,15 +446,9 @@ namespace App\Entity;
465
446
466
447
class Weather
467
448
{
468
- /**
469
- * @var float
470
- */
471
- private $temperature;
449
+ private float $temperature;
472
450
473
- /**
474
- * @var float
475
- */
476
- private $pressure;
451
+ private float $pressure;
477
452
478
453
// ...
479
454
}
@@ -495,19 +470,23 @@ use Doctrine\ORM\Mapping as ORM;
495
470
496
471
/**
497
472
* @ORM\Entity
498
- *
499
- * @ApiResource(
500
- * itemOperations={
501
- * "get",
502
- * "put",
503
- * "delete",
504
- * "get_weather": {
505
- * "method": "GET",
506
- * "path": "/places/{id}/weather",
507
- * "controller": GetWeather::class
508
- * }
509
- * }, collectionOperations={"get", "post"})
510
473
*/
474
+ #[ApiResource(
475
+ collectionOperations: [
476
+ 'get',
477
+ 'post',
478
+ ],
479
+ itemOperations: [
480
+ 'get',
481
+ 'put',
482
+ 'delete',
483
+ 'get_weather' => [
484
+ 'method' => 'GET',
485
+ 'path' => '/places/{id}/weather',
486
+ 'controller' => GetWeather::class,
487
+ ],
488
+ ],
489
+ )]
511
490
class Place
512
491
{
513
492
// ...
@@ -525,9 +504,7 @@ namespace App\Entity;
525
504
526
505
use ApiPlatform\Core\Annotation\ApiResource;
527
506
528
- /**
529
- * @ApiResource
530
- */
507
+ #[ApiResource]
531
508
class Weather
532
509
{
533
510
// ...
@@ -545,14 +522,14 @@ namespace App\Entity;
545
522
546
523
use ApiPlatform\Core\Annotation\ApiResource;
547
524
548
- /**
549
- * @ApiResource( itemOperations={
550
- * " get": {
551
- * " method": " GET" ,
552
- * " controller": SomeRandomController::class
553
- * }
554
- * })
555
- */
525
+ #[ApiResource(
526
+ itemOperations: [
527
+ ' get' => [
528
+ ' method' => ' GET' ,
529
+ ' controller' => SomeRandomController::class,
530
+ ],
531
+ ],
532
+ )]
556
533
class Weather
557
534
{
558
535
// ...
@@ -574,12 +551,9 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
574
551
575
552
final class SwaggerDecorator implements NormalizerInterface
576
553
{
577
- private $decorated;
578
-
579
- public function __construct(NormalizerInterface $decorated)
580
- {
581
- $this->decorated = $decorated;
582
- }
554
+ public function __construct(
555
+ private NormalizerInterface $decorated
556
+ ) {}
583
557
584
558
public function normalize($object, $format = null, array $context = [])
585
559
{
0 commit comments