Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Следующая версия
Предыдущая версия
php:symfony:операции_operations [2024/04/14 23:52] – создано mirocowphp:symfony:операции_operations [2024/04/15 21:07] (текущий) – [Операции / Operations] mirocow
Строка 4: Строка 4:
  
 <code php> <code php>
-#[ApiResource(operations: [+<?php 
 +// api/src/Entity/Book.php 
 +namespace App\Entity; 
 + 
 +use ApiPlatform\Metadata\ApiResource; 
 +use ApiPlatform\Metadata\Get; 
 +use ApiPlatform\Metadata\Post; 
 +use App\Controller\CreateBookPublication; 
 + 
 +#[ApiResource(types: ['https://schema.org/Book'], operations: [
     new Get(),     new Get(),
-    new Put(), +    new Post(name: 'publication'uriTemplate: '/books/{id}/publication')
-    new Patch()+
-    new Delete(), +
-    new GetCollection(), +
-    new Post(),+
 ])] ])]
 +class Book
 +{
 +    // ...
 +}
 +</code>
 +
 +<code php>
 +#[ApiResource(
 +    shortName: 'User',
 +    description: 'Utilisateurs',
 +    operations: [
 +        new Get(),
 +        new GetCollection(),
 +        new Post(),
 +        new Put(),
 +        new Patch(),
 +        new Delete(),
 +    ],
 +    normalizationContext: [
 +        'groups' => ['user:read'],
 +    ],
 +    denormalizationContext: [
 +        'groups' => ['user:write'],
 +    ],
 +    security: "is_granted('ROLE_USER')"
 +)]
 </code> </code>
      
 +===== #[ApiResource] =====
 +
 +2.7 ApiPlatform\Metadata\ApiResource вместо 2.6 ApiPlatform\Core\Annotation\ApiResource
 +
 +|Перед |После|
 +|iri: 'https://schema.org/Book' |types: ['https://schema.org/Book']|
 +|path: '/books/{id}/publication' |uriTemplate: '/books/{id}/publication'
 +|identifiers: [] |uriVariables: []|
 +|attributes: [] |extraProperties: []|
 +|attributes: ['validation_groups' => ['a', 'b']] |validationContext: ['groups' => ['a', 'b']]|
 +
 +===== #[ApiProperty] =====
 +
 +2.7 ApiPlatform\Metadata\ApiProperty вместо 2.6 ApiPlatform\Core\Annotation\ApiProperty
 +
 +| Перед    | После                   |
 +| iri:          | 'https://schema.org/Book'    | types: ['https://schema.org/Book']|
 +| type:         | 'string'                     | builtinTypes: ['string']|
 +
 +====== Symfony / API Platform ======
 +
 {{topic>[symfony]}} {{topic>[symfony]}}