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