Completed
Branch v2.0.0 (addc15)
by Alexander
03:27
created

AclManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 42
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A init() 0 18 3
A getAcl() 0 4 1
1
<?php
2
/**
3
 * @author Alexander Torosh <[email protected]>
4
 */
5
6
namespace Web;
7
8
use Phalcon\Acl\Adapter\Memory;
9
use Phalcon\Cache;
10
use Phalcon\Di\AbstractInjectionAware;
11
use Phalcon\Di\DiInterface;
12
use Phalcon\Events\Manager;
13
14
class AclManager extends AbstractInjectionAware
15
{
16
    const CACHE_KEY = 'acl-manager';
17
    const CACHE_LIFETIME = 7200;
18
19
    // @var $acl Memory
20
    private $acl;
21
22
    /**
23
     * AclManager constructor.
24
     */
25
    public function __construct(DiInterface $container, Manager $eventsManager)
26
    {
27
        $this->setDI($container);
28
        $this->init();
29
        $this->acl->setEventsManager($eventsManager);
30
    }
31
32
    public function init()
33
    {
34
        // @var $serverCache Cache
35
        $serverCache = $this->getDI()->get('serverCache');
36
        $cachedContents = $serverCache->get(self::CACHE_KEY);
37
        if (!$cachedContents) {
38
            // Read ACL file
39
            $aclObject = include __DIR__.'/../../web/config/acl.php';
40
            if ($aclObject) {
41
                $this->acl = $aclObject->acl;
42
43
                // Save it to serverCache
44
                $serverCache->set(self::CACHE_KEY, serialize($aclObject->acl), self::CACHE_LIFETIME);
45
            }
46
        } else {
47
            $this->acl = unserialize($cachedContents);
48
        }
49
    }
50
51
    public function getAcl()
52
    {
53
        return $this->acl;
54
    }
55
}
56