Completed
Pull Request — 1.x (#637)
by Daniel
14:10 queued 04:01
created

AbstractAdapter::getStorage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace ZfcUser\Authentication\Adapter;
4
5
use Zend\Authentication\Storage;
6
7
abstract class AbstractAdapter implements ChainableAdapter
8
{
9
    /**
10
     * @var Storage\StorageInterface
11
     */
12
    protected $storage;
13
14
    /**
15
     * Returns the persistent storage handler
16
     *
17
     * Session storage is used by default unless a different storage adapter has been set.
18
     *
19
     * @return Storage\StorageInterface
20
     */
21
    public function getStorage()
22
    {
23
        if (null === $this->storage) {
24
            $this->setStorage(new Storage\Session(get_class($this)));
25
        }
26
27
        return $this->storage;
28
    }
29
30
    /**
31
     * Sets the persistent storage handler
32
     *
33
     * @param  Storage\StorageInterface $storage
34
     * @return AbstractAdapter Provides a fluent interface
35
     */
36
    public function setStorage(Storage\StorageInterface $storage)
37
    {
38
        $this->storage = $storage;
39
        return $this;
40
    }
41
42
    /**
43
     * Check if this adapter is satisfied or not
44
     *
45
     * @return bool
46
     */
47
    public function isSatisfied()
48
    {
49
        $storage = $this->getStorage()->read();
50
        return (isset($storage['is_satisfied']) && true === $storage['is_satisfied']);
51
    }
52
53
    /**
54
     * Set if this adapter is satisfied or not
55
     *
56
     * @param bool $bool
57
     * @return AbstractAdapter
58
     */
59
    public function setSatisfied($bool = true)
60
    {
61
        $storage = $this->getStorage()->read() ?: array();
62
        $storage['is_satisfied'] = $bool;
63
        $this->getStorage()->write($storage);
64
        return $this;
65
    }
66
}
67