diff --git a/docs/Interceptor/security.md b/docs/Interceptor/security.md index 2e1a2ae..cfcf838 100644 --- a/docs/Interceptor/security.md +++ b/docs/Interceptor/security.md @@ -1,5 +1,42 @@ # Security +#[Security] attribute allows to check access. + +```php + +class AUseCase +{ + #[Security("is_granted('ROLE_1')")] + public function execute(UseCaseRequest $useCaseRequest) + { + // do things + + return $useCaseResponse; + } +} +``` + +## Other options : + +```php + +// You can use expressions to combine multiple checks, for instance role or voter: +#[Security("is_granted('ROLE_1') or is_granted('VOTER_1', request)")] + +// Beware of the following syntax +#[Security] + +// If it precedes a method named execute, __invoke or __construct, it will be interpreted as following: +#[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE')")] +public function execute(UseCaseRequest $useCaseRequest) + +// However, if it precedes a method with a different name, it will be interpreted as following: +#[Security("is_granted('ROLE_NAME_OF_CLASS_IN_SNAKE_CASE_PROCESS_ORDER')")] +public function processOrder(UseCaseRequest $useCaseRequest) +// Note that ROLE contains class name AND method name in snake case + +``` + @Security annotation allows to check access. ```php