AbstractAdapter::getIdentityAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Micro
7
 *
8
 * @copyright   Copryright (c) 2015-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     MIT https://opensource.org/licenses/MIT
10
 */
11
12
namespace Micro\Auth\Adapter;
13
14
use InvalidArgumentException;
15
16
abstract class AbstractAdapter implements AdapterInterface
17
{
18
    /**
19
     * Identity.
20
     *
21
     * @var string
22
     */
23
    protected $identifier;
24
25
    /**
26
     * attribute sync cache.
27
     *
28
     * @var int
29
     */
30
    protected $attr_sync_cache = 0;
31
32
    /**
33
     * attribute map.
34
     *
35
     * @var iterable
36
     */
37
    protected $map = [];
38
39
    /**
40
     * Identity attribute.
41
     *
42
     * @var string
43
     */
44
    protected $identity_attribute = 'uid';
45
46
    /**
47
     * Setup.
48
     *
49
     * @return bool
50
     */
51
    public function setup(): bool
52
    {
53
        return true;
54
    }
55
56
    /**
57
     * Get attribute sync cache.
58
     *
59
     * @return int
60
     */
61
    public function getAttributeSyncCache(): int
62
    {
63
        return $this->attr_sync_cache;
64
    }
65
66
    /**
67
     * Set options.
68
     *
69
     * @param iterable $config
70
     *
71
     * @return AdapterInterface
72
     */
73
    public function setOptions(? Iterable $config = null): AdapterInterface
74
    {
75
        if (null === $config) {
76
            return $this;
77
        }
78
79
        foreach ($config as $option => $value) {
80
            switch ($option) {
81
                case 'map':
82
                    $this->map = $value;
83
84
                break;
85
                case 'attr_sync_cache':
86
                    $this->attr_sync_cache = (int) $value;
87
88
                break;
89
                case 'identity_attribute':
90
                    $this->identity_attribute = $value;
91
92
                break;
93
                default:
94
                    throw new InvalidArgumentException('unknown option '.$option.' given');
95
            }
96
        }
97
98
        return $this;
99
    }
100
101
    /**
102
     * Get identifier.
103
     *
104
     * @return string
105
     */
106
    public function getIdentityAttribute(): string
107
    {
108
        return $this->identity_attribute;
109
    }
110
111
    /**
112
     * Get identifier.
113
     *
114
     * @return string
115
     */
116
    public function getIdentifier(): string
117
    {
118
        return $this->identifier;
119
    }
120
121
    /**
122
     * Get attribute map.
123
     *
124
     * @return iterable
125
     */
126
    public function getAttributeMap(): Iterable
127
    {
128
        return $this->map;
129
    }
130
}
131