Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PolicyManager
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 allowed
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\Core\Policies;
3
4use Apie\Core\Context\ApieContext;
5
6class PolicyManager
7{
8    public function __construct(
9        private readonly PolicyProviderInterface $policyProvider,
10        private readonly bool $defaultAllow = true,
11    ) {
12    }
13
14    public function allowed(ApieContext $apieContext, string $action): bool
15    {
16        $policy = $this->policyProvider->getPolicyFor($apieContext, $action);
17
18        if (is_callable([$policy, $action])) {
19            // TODO: use reflection to determine the arguments to pass here
20            return $policy->{$action}();
21        }
22        return $this->defaultAllow;
23    }
24}