|
1
|
|
|
<?php /** MicroACL */ |
|
2
|
|
|
|
|
3
|
|
|
namespace Micro\Auth\Drivers; |
|
4
|
|
|
|
|
5
|
|
|
use Micro\Db\Adapter; |
|
6
|
|
|
use Micro\Db\Drivers\IDriver; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Abstract ACL class file. |
|
10
|
|
|
* |
|
11
|
|
|
* Base logic for a ACL security |
|
12
|
|
|
* |
|
13
|
|
|
* @author Oleg Lunegov <[email protected]> |
|
14
|
|
|
* @link https://github.com/linpax/microphp-framework |
|
15
|
|
|
* @copyright Copyright (c) 2013 Oleg Lunegov |
|
16
|
|
|
* @license https://github.com/linpax/microphp-framework/blob/master/LICENSE |
|
17
|
|
|
* @package Micro |
|
18
|
|
|
* @subpackage Auth\Drivers |
|
19
|
|
|
* @version 1.0 |
|
20
|
|
|
* @since 1.0 |
|
21
|
|
|
* @abstract |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class Acl implements \Micro\Auth\Adapter |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var IDriver $db */ |
|
26
|
|
|
protected $db; |
|
27
|
|
|
/** @var string $groupTable name of group table */ |
|
28
|
|
|
protected $groupTable; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Base constructor for ACL, make acl_user table if exists |
|
33
|
|
|
* |
|
34
|
|
|
* @access public |
|
35
|
|
|
* |
|
36
|
|
|
* @param Adapter $db |
|
37
|
|
|
* @param array $params config array |
|
38
|
|
|
* |
|
39
|
|
|
* @result void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(Adapter $db, array $params = []) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->db = $db->getDriver(); |
|
44
|
|
|
|
|
45
|
|
|
if (!empty($params['groupTable'])) { |
|
46
|
|
|
$this->groupTable = $params['groupTable']; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (!$this->db->tableExists('acl_user')) { |
|
50
|
|
|
$this->db->createTable('acl_user', [ |
|
51
|
|
|
'`id` int(10) unsigned NOT NULL AUTO_INCREMENT', |
|
52
|
|
|
'`user` int(11) unsigned NOT NULL', |
|
53
|
|
|
'`role` int(11) unsigned DEFAULT NULL', |
|
54
|
|
|
'`perm` int(11) unsigned DEFAULT NULL', |
|
55
|
|
|
'PRIMARY KEY (`id`)' |
|
56
|
|
|
], 'ENGINE=MyISAM DEFAULT CHARSET=utf8'); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get permissions in role |
|
62
|
|
|
* |
|
63
|
|
|
* @access protected |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $role role name |
|
66
|
|
|
* |
|
67
|
|
|
* @return array |
|
68
|
|
|
* @abstract |
|
69
|
|
|
*/ |
|
70
|
|
|
abstract protected function rolePerms($role); |
|
71
|
|
|
} |
|
72
|
|
|
|