AbstractStorage::has()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/**
4
 * AppserverIo\Storage\AbstractStorage
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      http://github.com/appserver-io/storage
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Storage;
22
23
/**
24
 * A abstract storage implementation.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2015 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      http://github.com/appserver-io/storage
30
 * @link      http://www.appserver.io
31
 */
32
abstract class AbstractStorage implements StorageInterface
33
{
34
35
    /**
36
     * Register the trait that provides basic storage functionality.
37
     *
38
     * @var \Trait
39
     */
40
    use StorageTrait;
41
42
    /**
43
     * A storage backend, a \Stackable for example.
44
     *
45
     * @var mixed
46
     */
47
    protected $storage;
48
49
    /**
50
     * Passes the configuration and initializes the storage.
51
     */
52
    public function __construct()
53
    {
54
        $this->init();
55
        $this->flush();
56
    }
57
58
    /**
59
     * Restores the storage after the instance has been recovered
60
     * from sleep.
61
     *
62
     * @return void
63
     */
64
    public function __wakeup()
65
    {
66
        $this->init();
67
    }
68
69
    /**
70
     * Initializes the storage when the instance is constructed and the
71
     * __wakeup() method is invoked.
72
     *
73
     * @return void
74
     */
75
    abstract public function init();
76
77
    /**
78
     * (non-PHPdoc)
79
     *
80
     * @return void
81
     * @see \AppserverIo\Storage\StorageInterface::collectGarbage()
82
     */
83
    public function collectGarbage()
84
    {
85
        // nothing to do here, because gc is handled by memcache
86
    }
87
88
    /**
89
     * (non-PHPdoc)
90
     *
91
     * @param string $tag The tag to search for
92
     *
93
     * @return array An array with the identifier (key) and content (value) of all matching entries. An empty array if no entries matched
94
     * @see \AppserverIo\Storage\StorageInterface::getByTag()
95
     */
96
    public function getByTag($tag)
97
    {
98
        return $this->get($tag);
99
    }
100
101
    /**
102
     * (non-PHPdoc)
103
     *
104
     * @param string $entryIdentifier An identifier specifying the cache entry
105
     *
106
     * @return boolean TRUE if such an entry exists, FALSE if not
107
     * @see \AppserverIo\Storage\StorageInterface::has()
108
     */
109
    public function has($entryIdentifier)
110
    {
111
        if ($this->get($entryIdentifier) !== false) {
112
            return true;
113
        }
114
        return false;
115
    }
116
117
    /**
118
     * Injects the storage instance to use.
119
     *
120
     * @param mixed $storage The storge instance to use
121
     *
122
     * @return void
123
     */
124
    public function injectStorage($storage)
125
    {
126
        $this->storage = $storage;
127
    }
128
129
    /**
130
     * (non-PHPdoc)
131
     *
132
     * @return mixed The storage object itself
133
     * @see \AppserverIo\Storage\StorageInterface::getStorage()
134
     */
135
    public function getStorage()
136
    {
137
        return $this->storage;
138
    }
139
}
140