-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigProps.php
More file actions
103 lines (97 loc) · 3.71 KB
/
ConfigProps.php
File metadata and controls
103 lines (97 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
declare(strict_types=1);
namespace MaplePHP\Unitary\Config;
use InvalidArgumentException;
use MaplePHP\Emitron\AbstractConfigProps;
/**
* Defines the set of allowed configuration properties and CLI arguments.
*
* CLI arguments with matching property names will override configuration file values.
*
* Note:
* - All properties are nullable, indicating they have not been explicitly set.
* - Null values allow the system to distinguish between "not provided" and "intentionally set".
* - Do not use array values or multiple data types
*/
class ConfigProps extends AbstractConfigProps
{
public ?string $discoverPattern = null;
public ?string $exclude = null;
public ?string $show = null;
public ?string $timezone = null;
public ?string $locale = null;
public ?string $type = null;
public ?string $path = null;
public ?int $exitCode = null;
public ?bool $verbose = null;
public ?bool $alwaysShowFiles = null;
public ?bool $errorsOnly = null;
public ?bool $smartSearch = null;
public ?bool $failFast = null;
public ?string $helpController = null;
public ?array $configuration = null;
/**
* Hydrate the properties/object with expected data, and handle unexpected data
*
* @param string|bool $key
* @param mixed $value
* @return void
*/
protected function propsHydration(string|bool $key, mixed $value): void
{
switch ($key) {
case 'path':
$this->path = (!is_string($value) || $value === '') ? null : $value;
break;
case 'discoverPattern':
$this->discoverPattern = (!is_string($value) || $value === '') ? null : $value;
break;
case 'exclude':
$this->exclude = (!is_string($value) || $value === '') ? null : $value;
break;
case 'show':
$this->show = (!is_string($value) || $value === '') ? null : $value;
break;
case 'type':
$this->type = (!is_string($value) || $value === '') ? null : $value;
break;
case 'helpController':
$this->helpController = (!is_string($value) || $value === '') ? null : $value;
break;
case 'timezone':
// The default timezone is 'CET'
$this->timezone = (!is_string($value) || $value === '') ? 'Europe/Stockholm' : $value;
break;
case 'locale':
// The default timezone is 'CET'
$this->locale = (!is_string($value) || $value === '') ? 'en_US' : $value;
if(!$this->isValidLocale($this->locale)) {
throw new InvalidArgumentException(
"Invalid locale '{$this->locale}'. Expected format like 'en_US' (language_COUNTRY)."
);
}
break;
case 'exitCode':
$this->exitCode = ($value === null) ? null : (int)$value;
break;
case 'verbose':
$this->verbose = $this->dataToBool($value);
break;
case 'alwaysShowFiles':
$this->alwaysShowFiles = $this->dataToBool($value);
break;
case 'smartSearch':
$this->smartSearch = $this->dataToBool($value);
break;
case 'errorsOnly':
$this->errorsOnly = $this->dataToBool($value);
break;
case 'failFast':
$this->failFast = $this->dataToBool($value);
break;
case 'configuration':
$this->configuration = (array)$value;
break;
}
}
}