| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Copyright Andreas Heigl <andreas@heigl.org> |
| 5 |
* |
| 6 |
* Licensed under the MIT-license. For details see the included file LICENSE.md |
| 7 |
*/ |
| 8 |
|
| 9 |
declare(strict_types=1); |
| 10 |
|
| 11 |
namespace Org_Heigl\AuthLdap; |
| 12 |
|
| 13 |
use Org_Heigl\AuthLdap\Exception\UnknownOption; |
| 14 |
|
| 15 |
use function array_key_exists; |
| 16 |
|
| 17 |
class Options |
| 18 |
{ |
| 19 |
public const ENABLED = 'Enabled'; |
| 20 |
public const CACHE_PW = 'CachePW'; |
| 21 |
public const URI = 'URI'; |
| 22 |
public const URI_SEPARATOR = 'URISeparator'; |
| 23 |
public const FILTER = 'Filter'; |
| 24 |
public const NAME_ATTR = 'NameAttr'; |
| 25 |
public const SEC_NAME = 'SecName'; |
| 26 |
public const UID_ATTR = 'UidAttr'; |
| 27 |
public const MAIL_ATTR = 'MailAttr'; |
| 28 |
public const WEB_ATTR = 'WebAttr'; |
| 29 |
public const GROUPS = 'Groups'; |
| 30 |
public const DEBUG = 'Debug'; |
| 31 |
public const GROUP_ATTR = 'GroupAttr'; |
| 32 |
public const GROUP_FILTER = 'GroupFilter'; |
| 33 |
public const DEFAULT_ROLE = 'DefaultRole'; |
| 34 |
public const GROUP_ENABLE = 'GroupEnable'; |
| 35 |
public const GROUP_OVER_USER = 'GroupOverUser'; |
| 36 |
public const VERSION = 'Version'; |
| 37 |
public const DO_NOT_OVERWRITE_NON_LDAP_USERS = 'DoNotOverwriteNonLdapUsers'; |
| 38 |
|
| 39 |
private array $settings = [ |
| 40 |
'Enabled' => false, |
| 41 |
'CachePW' => false, |
| 42 |
'URI' => '', |
| 43 |
'URISeparator' => ' ', |
| 44 |
'Filter' => '', // '(uid=%s)' |
| 45 |
'NameAttr' => '', // 'name' |
| 46 |
'SecName' => '', |
| 47 |
'UidAttr' => '', // 'uid' |
| 48 |
'MailAttr' => '', // 'mail' |
| 49 |
'WebAttr' => '', |
| 50 |
'Groups' => [], |
| 51 |
'Debug' => false, |
| 52 |
'GroupAttr' => '', // 'gidNumber' |
| 53 |
'GroupFilter' => '', // '(&(objectClass=posixGroup)(memberUid=%s))' |
| 54 |
'DefaultRole' => '', |
| 55 |
'GroupEnable' => true, |
| 56 |
'GroupOverUser' => true, |
| 57 |
'Version' => 1, |
| 58 |
'DoNotOverwriteNonLdapUsers' => false, |
| 59 |
]; |
| 60 |
|
| 61 |
public function get(string $key) |
| 62 |
{ |
| 63 |
if (! array_key_exists($key, $this->settings)) { |
| 64 |
throw UnknownOption::withKey($key); |
| 65 |
} |
| 66 |
|
| 67 |
return $this->settings[$key]; |
| 68 |
} |
| 69 |
|
| 70 |
public function has(string $key): bool |
| 71 |
{ |
| 72 |
return array_key_exists($key, $this->settings); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* @param mixed $value |
| 77 |
*/ |
| 78 |
public function set(string $key, $value): void |
| 79 |
{ |
| 80 |
if (! array_key_exists($key, $this->settings)) { |
| 81 |
throw UnknownOption::withKey($key); |
| 82 |
} |
| 83 |
|
| 84 |
$this->settings[$key] = $value; |
| 85 |
} |
| 86 |
|
| 87 |
public function toArray(): array |
| 88 |
{ |
| 89 |
return $this->settings; |
| 90 |
} |
| 91 |
} |
| 92 |
|