|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Application\Packages\Commands; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2020 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Limoncello\Contracts\Settings\Packages\CommandSettingsInterface; |
|
22
|
|
|
use Limoncello\Contracts\Settings\SettingsInterface; |
|
23
|
|
|
use function assert; |
|
24
|
|
|
use function is_array; |
|
25
|
|
|
use function is_int; |
|
26
|
|
|
use function is_string; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @package Limoncello\Application |
|
30
|
1 |
|
*/ |
|
31
|
|
|
class CommandSettings implements SettingsInterface, CommandSettingsInterface |
|
32
|
1 |
|
{ |
|
33
|
|
|
/** |
|
34
|
1 |
|
* @inheritdoc |
|
35
|
1 |
|
*/ |
|
36
|
|
|
final public function get(array $appConfig): array |
|
37
|
1 |
|
{ |
|
38
|
1 |
|
$defaults = $this->getSettings(); |
|
39
|
1 |
|
|
|
40
|
1 |
|
$userIdentity = $defaults[static::KEY_IMPERSONATE_AS_USER_IDENTITY] ?? null; |
|
41
|
|
|
$userProperties = $defaults[static::KEY_IMPERSONATE_WITH_USER_PROPERTIES] ?? null; |
|
42
|
1 |
|
|
|
43
|
|
|
assert( |
|
44
|
1 |
|
$userIdentity === null || (is_string($userIdentity) === true && empty($userIdentity) === false) || |
|
45
|
|
|
is_int($userIdentity) === true, |
|
46
|
|
|
'Invalid Impersonation User Identity.' |
|
47
|
|
|
); |
|
48
|
|
|
assert(is_array($userProperties) === true, 'Invalid Impersonation User Properties.'); |
|
49
|
|
|
|
|
50
|
1 |
|
return $defaults; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
/** |
|
54
|
1 |
|
* @return array |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function getSettings(): array |
|
57
|
|
|
{ |
|
58
|
|
|
return [ |
|
59
|
|
|
static::KEY_IMPERSONATE_AS_USER_IDENTITY => null, |
|
60
|
|
|
static::KEY_IMPERSONATE_WITH_USER_PROPERTIES => [], |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|