1 | <?php |
||
16 | class Guard extends Component implements GuardInterface |
||
17 | { |
||
18 | /** |
||
19 | * @var ActorInterface|null |
||
20 | */ |
||
21 | private $actor = null; |
||
22 | |||
23 | /** |
||
24 | * Session specific roles. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | private $roles = []; |
||
29 | |||
30 | /** |
||
31 | * @var PermissionsInterface |
||
32 | */ |
||
33 | private $permissions = null; |
||
34 | |||
35 | /** |
||
36 | * @param array $roles Session specific roles. |
||
37 | * @param ActorInterface $actor |
||
38 | * @param PermissionsInterface $permissions |
||
39 | */ |
||
40 | public function __construct( |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | public function allows(string $permission, array $context = []): bool |
||
74 | |||
75 | /** |
||
76 | * Currently active actor/session roles. |
||
77 | * |
||
78 | * @return array |
||
79 | * |
||
80 | * @throws GuardException |
||
81 | */ |
||
82 | public function getRoles(): array |
||
86 | |||
87 | /** |
||
88 | * Create instance of guard with session specific roles (existed roles will be droppped). |
||
89 | * |
||
90 | * @param array $roles |
||
91 | * |
||
92 | * @return self |
||
93 | */ |
||
94 | public function withRoles(array $roles): Guard |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | * |
||
105 | * @throws GuardException |
||
106 | */ |
||
107 | public function getActor(): ActorInterface |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function withActor(ActorInterface $actor): GuardInterface |
||
126 | } |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: