1 | <?php |
||
20 | class Authorize |
||
21 | { |
||
22 | /** |
||
23 | * @var PermissionMapperInterface Permission Mapper |
||
24 | */ |
||
25 | protected $permissionMapper; |
||
26 | |||
27 | /** |
||
28 | * @var Authenticate Current authentication status |
||
29 | */ |
||
30 | protected $authenticate; |
||
31 | |||
32 | /** |
||
33 | * @var int User id |
||
34 | */ |
||
35 | protected $userId = 0; |
||
36 | |||
37 | /** |
||
38 | * @var array User/Permission hash table |
||
39 | */ |
||
40 | protected $hashTable; |
||
41 | |||
42 | /** |
||
43 | * Class Constructor. |
||
44 | * <pre><code class="php">use Linna\Auth\Authenticate; |
||
45 | * use Linna\Auth\Authorize; |
||
46 | * use Linna\Auth\Password; |
||
47 | * use Linna\Session\Session; |
||
48 | * |
||
49 | * //your concrete permission mapper |
||
50 | * use YourApp\Mapper\PermissionMapper; |
||
51 | * |
||
52 | * $password = new Password(); |
||
53 | * $session = new Session(); |
||
54 | * |
||
55 | * $authenticate = new Authenticate($session, $password); |
||
56 | * $permissionMapper = new PermissionMapper(); |
||
57 | * |
||
58 | * $authorize = new Authorize($authenticate, $permissionMapper); |
||
59 | * </code></pre> |
||
60 | * |
||
61 | * @param Authenticate $authenticate |
||
62 | * @param PermissionMapperInterface $permissionMapper |
||
63 | */ |
||
64 | 4 | public function __construct(Authenticate $authenticate, PermissionMapperInterface $permissionMapper) |
|
73 | |||
74 | /** |
||
75 | * Check if authenticated user has a permission. |
||
76 | * <pre><code class="php">$authorize = new Authorize($authenticate, $permissionMapper); |
||
77 | * |
||
78 | * //with this example, the class checks if the authenticated |
||
79 | * //user has the permission 'update user'. |
||
80 | * $authorize->can('update user'); |
||
81 | * </code></pre> |
||
82 | * |
||
83 | * @param string $permissionName |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 3 | public function can(string $permissionName) : bool |
|
107 | } |
||
108 |