File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# Security
22
3+ #[ Security] attribute allows to check access.
4+
5+ ``` php
6+
7+ class AUseCase
8+ {
9+ #[Security("is_granted('ROLE_1')")]
10+ public function execute(UseCaseRequest $useCaseRequest)
11+ {
12+ // do things
13+
14+ return $useCaseResponse;
15+ }
16+ }
17+ ```
18+
19+ ## Other options :
20+
21+ ``` php
22+
23+ // You can use expressions to combine multiple checks, for instance role or voter:
24+ #[Security("is_granted('ROLE_1') or is_granted('VOTER_1', request)")]
25+
26+ // Beware of the following syntax
27+ #[Security]
28+
29+ // If it precedes a method named execute, __invoke or __construct, it will be interpreted as following:
30+ #[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE')")]
31+ public function execute(UseCaseRequest $useCaseRequest)
32+
33+ // However, if it precedes a method with a different name, it will be interpreted as following:
34+ #[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE_PROCESS_ORDER')")]
35+ public function processOrder(UseCaseRequest $useCaseRequest)
36+ // Note that ROLE contains class name AND method name in snake case
37+
38+ ```
39+
340@Security annotation allows to check access.
441
542``` php
You can’t perform that action at this time.
0 commit comments