Skip to content

Commit 04ea076

Browse files
KDederichsnesl247
authored andcommitted
feat(subresource): Link security (#1692)
* feat(subresource): Link security * feat(subresource): Link security * Update core/subresources.md Fix spelling Co-authored-by: Alexander Kim <[email protected]> --------- Co-authored-by: Alexander Kim <[email protected]>
1 parent 4bba121 commit 04ea076

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core/subresources.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,28 @@ class Company {
332332
// ...
333333
}
334334
```
335+
336+
## Security
337+
338+
In order to use Symfony's built-in security system on subresources the security option of the `Link` attribute can be used.
339+
340+
To restrict the access to a subresource based on the parent object simply use the Symfony expression language as you would do normally, with the exception that the name defined in `toProperty` or `fromProperty` is used to access the object.
341+
342+
Alternatively you can also use the `securityObjectName` to set a custom name
343+
344+
```php
345+
<?php
346+
#[ApiResource(
347+
uriTemplate: '/employees/{employeeId}/company',
348+
uriVariables: [
349+
'employeeId' => new Link(fromClass: Employee::class, toProperty: 'company', security: "is_granted(some_voter, company)"),
350+
],
351+
operations: [
352+
new Get()
353+
]
354+
)]
355+
356+
class Company {
357+
// ...
358+
}
359+
```

0 commit comments

Comments
 (0)