Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| PermissionExtension | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| can | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace AppDemo\Shared\Presentation\Twig; |
| 11 | |
| 12 | use AppDemo\Shared\Domain\Interface\UserContextProviderInterface; |
| 13 | use Override; |
| 14 | use Twig\Extension\AbstractExtension; |
| 15 | use Twig\TwigFunction; |
| 16 | |
| 17 | final class PermissionExtension extends AbstractExtension |
| 18 | { |
| 19 | public function __construct( |
| 20 | private readonly UserContextProviderInterface $userContextProvider |
| 21 | ) {} |
| 22 | |
| 23 | #[Override] |
| 24 | public function getFunctions(): array |
| 25 | { |
| 26 | return [ |
| 27 | new TwigFunction('can', $this->can(...)), |
| 28 | ]; |
| 29 | } |
| 30 | |
| 31 | public function can(string $permission): bool |
| 32 | { |
| 33 | $userContext = $this->userContextProvider->getCurrentUserContext(); |
| 34 | |
| 35 | return $userContext->can($permission); |
| 36 | } |
| 37 | } |