Skip to content

Commit 6e19548

Browse files
docs: update guide
1 parent 3d98358 commit 6e19548

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

src/Metadata/ApiProperty.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,89 @@ public function __construct(
105105
private ?array $openapiContext = null,
106106
private ?array $jsonSchemaContext = null,
107107
private ?bool $push = null,
108+
/**
109+
* The `security` option defines the access to the current property, on normalization process, based on Symfony Security.
110+
* It receives an `object` variable related to the current object, and a `property` variable related to the current property.
111+
*
112+
* <CodeSelector>
113+
* ```php
114+
* <?php
115+
* // api/src/Entity/Review.php
116+
* use ApiPlatform\Metadata\ApiProperty;
117+
* use ApiPlatform\Metadata\ApiResource;
118+
*
119+
* #[ApiResource]
120+
* class Review
121+
* {
122+
* #[ApiProperty(security: 'is_granted("ROLE_ADMIN")')]
123+
* public string $letter;
124+
* }
125+
* ```
126+
*
127+
* ```yaml
128+
* # api/config/api_platform/properties.yaml
129+
* properties:
130+
* App\Entity\Review:
131+
* letter:
132+
* security: 'is_granted("ROLE_ADMIN")'
133+
* ```
134+
*
135+
* ```xml
136+
* <?xml version="1.0" encoding="UTF-8" ?>
137+
* <!-- api/config/api_platform/properties.xml -->
138+
*
139+
* <properties
140+
* xmlns="https://api-platform.com/schema/metadata/properties-3.0"
141+
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
142+
* xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
143+
* https://api-platform.com/schema/metadata/properties-3.0.xsd">
144+
* <property resource="App\Entity\Review" name="letter" security="is_granted('ROLE_ADMIN')" />
145+
* </properties>
146+
* ```
147+
* </CodeSelector>
148+
*/
108149
private ?string $security = null,
150+
/**
151+
* The `securityPostDenormalize` option defines access to the current property after the denormalization process, based on Symfony Security.
152+
* It receives an `object` variable related to the current object, and a `property` variable related to the current property.
153+
*
154+
* <CodeSelector>
155+
* ```php
156+
* <?php
157+
* // api/src/Entity/Review.php
158+
* use ApiPlatform\Metadata\ApiProperty;
159+
* use ApiPlatform\Metadata\ApiResource;
160+
*
161+
* #[ApiResource]
162+
* class Review
163+
* {
164+
* #[ApiProperty(securityPostDenormalize: 'is_granted("ROLE_ADMIN")')]
165+
* public string $letter;
166+
* }
167+
* ```
168+
*
169+
* ```yaml
170+
* # api/config/api_platform/properties.yaml
171+
* properties:
172+
* App\Entity\Review:
173+
* letter:
174+
* securityPostDenormalize: 'is_granted("ROLE_ADMIN")'
175+
* ```
176+
*
177+
* ```xml
178+
* <?xml version="1.0" encoding="UTF-8" ?>
179+
* <!-- api/config/api_platform/properties.xml -->
180+
*
181+
* <properties
182+
* xmlns="https://api-platform.com/schema/metadata/properties-3.0"
183+
* xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
184+
* xsi:schemaLocation="https://api-platform.com/schema/metadata/properties-3.0
185+
* https://api-platform.com/schema/metadata/properties-3.0.xsd">
186+
* <property resource="App\Entity\Review" name="letter" securityPostDenormalize="is_granted('ROLE_ADMIN')" />
187+
* </properties>
188+
* ```
189+
* </CodeSelector>
190+
*/
109191
private ?string $securityPostDenormalize = null,
110192
private array|string|null $types = null,
111193
/*

0 commit comments

Comments
 (0)