Passed
Push — 3.0 ( d2a6b7...b247bd )
by Rubén
04:14
created

LdapParams::setType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2018, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Providers\Auth\Ldap;
26
27
/**
28
 * Class LdapParams
29
 *
30
 * @package SP\Providers\Auth\Ldap
31
 */
32
final class LdapParams
33
{
34
    const REGEX_SERVER = '(?<server>(?:(?<proto>ldap|ldaps):\/\/)?[\w\.\-]+)(?::(?<port>\d+))?';
35
36
    /**
37
     * @var string
38
     */
39
    protected $server;
40
    /**
41
     * @var int
42
     */
43
    protected $port = 389;
44
    /**
45
     * @var string
46
     */
47
    protected $searchBase;
48
    /**
49
     * @var string
50
     */
51
    protected $bindDn;
52
    /**
53
     * @var string
54
     */
55
    protected $bindPass;
56
    /**
57
     * @var string
58
     */
59
    protected $group;
60
    /**
61
     * @var int
62
     */
63
    protected $type;
64
    /**
65
     * @var bool
66
     */
67
    protected $tlsEnabled = false;
68
69
    /**
70
     * Devolver el puerto del servidor si está establecido
71
     *
72
     * @param $server
73
     *
74
     * @return array|false
75
     */
76
    public static function getServerAndPort($server)
77
    {
78
        return preg_match('#' . self::REGEX_SERVER . '#i', $server, $matches) ? $matches : false;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function getPort()
85
    {
86
        return $this->port;
87
    }
88
89
    /**
90
     * @param int $port
91
     *
92
     * @return LdapParams
93
     */
94
    public function setPort($port)
95
    {
96
        $this->port = $port;
97
98
        return $this;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function getSearchBase()
105
    {
106
        return $this->searchBase;
107
    }
108
109
    /**
110
     * @param string $searchBase
111
     *
112
     * @return LdapParams
113
     */
114
    public function setSearchBase($searchBase)
115
    {
116
        $this->searchBase = $searchBase;
117
        return $this;
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getBindDn()
124
    {
125
        return $this->bindDn;
126
    }
127
128
    /**
129
     * @param string $bindDn
130
     *
131
     * @return LdapParams
132
     */
133
    public function setBindDn($bindDn)
134
    {
135
        $this->bindDn = $bindDn;
136
        return $this;
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getBindPass()
143
    {
144
        return $this->bindPass;
145
    }
146
147
    /**
148
     * @param string $bindPass
149
     *
150
     * @return LdapParams
151
     */
152
    public function setBindPass($bindPass)
153
    {
154
        $this->bindPass = $bindPass;
155
        return $this;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getGroup()
162
    {
163
        return $this->group;
164
    }
165
166
    /**
167
     * @param string $group
168
     *
169
     * @return LdapParams
170
     */
171
    public function setGroup($group)
172
    {
173
        $this->group = $group;
174
        return $this;
175
    }
176
177
    /**
178
     * @return string
179
     */
180
    public function getServer()
181
    {
182
        return $this->server;
183
    }
184
185
    /**
186
     * @param string $server
187
     *
188
     * @return LdapParams
189
     */
190
    public function setServer($server)
191
    {
192
        $this->server = $server;
193
194
        return $this;
195
    }
196
197
    /**
198
     * @return int
199
     */
200
    public function getType()
201
    {
202
        return $this->type;
203
    }
204
205
    /**
206
     * @param int $type
207
     *
208
     * @return LdapParams
209
     */
210
    public function setType($type)
211
    {
212
        $this->type = (int)$type;
213
214
        return $this;
215
    }
216
217
    /**
218
     * @return bool
219
     */
220
    public function isTlsEnabled(): bool
221
    {
222
        return $this->tlsEnabled;
223
    }
224
225
    /**
226
     * @param bool $tlsEnabled
227
     *
228
     * @return LdapParams
229
     */
230
    public function setTlsEnabled(bool $tlsEnabled)
231
    {
232
        $this->tlsEnabled = $tlsEnabled;
233
234
        return $this;
235
    }
236
237
}