summaryrefslogtreecommitdiff
path: root/app/Core/Cache.php
blob: 670a76e0c6cdde08c508417d392684a3b4c4f698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

namespace Core;

use Pimple\Container;

abstract class Cache
{
    /**
     * Container instance
     *
     * @access protected
     * @var \Pimple\Container
     */
    protected $container;

    abstract public function init();
    abstract public function set($key, $value);
    abstract public function get($key);
    abstract public function flush();
    abstract public function remove($key);

    /**
     * Constructor
     *
     * @access public
     * @param  \Pimple\Container   $container
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
        $this->init();
    }

    /**
     * Proxy cache
     *
     * Note: Arguments must be scalar types
     *
     * @access public
     * @param  string    $container    Container name
     * @param  string    $method       Container method
     * @return mixed
     */
    public function proxy($container, $method)
    {
        $args = func_get_args();
        $key = 'proxy_'.implode('_', $args);
        $result = $this->get($key);

        if ($result === null) {
            $result = call_user_func_array(array($this->container[$container], $method), array_splice($args, 2));
            $this->set($key, $result);
        }

        return $result;
    }
}