1 | <?php |
||
15 | class CheckPermissionsMiddleware implements Middleware |
||
16 | { |
||
17 | private User $user; |
||
|
|||
18 | private Endpoint $endpoint; |
||
19 | |||
20 | public function __construct(Endpoint $endpoint, User $user) |
||
21 | { |
||
22 | $this->endpoint = $endpoint; |
||
23 | $this->user = $user; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @inheritDoc |
||
28 | */ |
||
29 | public function execute($command, callable $next) |
||
30 | { |
||
31 | foreach ($this->endpoint->permissions as $permission) { |
||
32 | if (! $this->user->can($permission)) { |
||
33 | throw new InsufficientPermissionsException($permission); |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return $next($command); |
||
38 | } |
||
39 | } |
||
40 |