Completed
Pull Request — final (#299)
by Georges
03:16
created

phpFastCacheAbstractProxy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 32
rs 10
wmc 3
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 8 2
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 *
13
 */
14
namespace phpFastCache\Proxy;
15
16
use phpFastCache\Cache\ExtendedCacheItemInterface;
17
use phpFastCache\CacheManager;
18
use phpFastCache\Entities\driverStatistic;
19
use Psr\Cache\CacheItemInterface;
20
21
/**
22
 * Class phpFastCache
23
 *
24
 * Handle methods using annotations for IDE
25
 * because they're handled by __call()
26
 * Check out ExtendedCacheItemInterface to see all
27
 * the drivers methods magically implemented
28
 *
29
 * @method ExtendedCacheItemInterface getItem($key) Retrieve an item and returns an empty item if not found
30
 * @method ExtendedCacheItemInterface[] getItems(array $keys) Retrieve an item and returns an empty item if not found
31
 * @method bool hasItem() hasItem($key) Tests if an item exists
32
 * @method bool deleteItem(string $key) Delete an item
33
 * @method bool deleteItems(array $keys) Delete some items
34
 * @method bool save(CacheItemInterface $item) Save an item
35
 * @method bool saveDeferred(CacheItemInterface $item) Sets a cache item to be persisted later
36
 * @method bool commit() Persists any deferred cache items
37
 * @method bool clear() Allow you to completely empty the cache and restart from the beginning
38
 * @method driverStatistic stats() Allow you to completely empty the cache and restart from the beginning
39
 * @method ExtendedCacheItemInterface getItemsByTag($tagName) Return items by a tag
40
 * @method ExtendedCacheItemInterface[] getItemsByTags(array $tagNames) Return items by some tags
41
 * @method bool deleteItemsByTag($tagName) Delete items by a tag
42
 * @method bool deleteItemsByTags(array $tagNames) // Delete items by some tags
43
 * @method void incrementItemsByTag($tagName, $step = 1) // Increment items by a tag
44
 * @method void incrementItemsByTags(array $tagNames, $step = 1) // Increment items by some tags
45
 * @method void decrementItemsByTag($tagName, $step = 1) // Decrement items by a tag
46
 * @method void decrementItemsByTags(array $tagNames, $step = 1) // Decrement items by some tags
47
 * @method void appendItemsByTag($tagName, $data) // Append items by a tag
48
 * @method void appendItemsByTags(array $tagNames, $data) // Append items by a tags
49
 * @method void prependItemsByTag($tagName, $data) // Prepend items by a tag
50
 * @method void prependItemsByTags(array $tagNames, $data) // Prepend items by a tags
51
 */
52
abstract class phpFastCacheAbstractProxy
53
{
54
    /**
55
     * @var \phpFastCache\Cache\ExtendedCacheItemPoolInterface
56
     */
57
    protected $instance;
58
59
    /**
60
     * phpFastCache constructor.
61
     * @param string $driver
62
     * @param array $config
63
     */
64
    public function __construct($driver = 'auto', array $config = [])
65
    {
66
        $this->instance = CacheManager::getInstance($driver, $config);
67
    }
68
69
    /**
70
     * @param $name
71
     * @param $args
72
     * @return mixed
73
     * @throws \BadMethodCallException
74
     */
75
    public function __call($name, $args)
76
    {
77
        if(method_exists($this->instance, $name)){
78
            return call_user_func_array([$this->instance, $name], $args);
79
        }else{
80
            throw new \BadMethodCallException(sprintf('Method %s does not exists', $name));
81
        }
82
    }
83
}
84