1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace InputGuard; |
5
|
|
|
|
6
|
|
|
use InputGuard\Guards\BoolGuard; |
7
|
|
|
use InputGuard\Guards\FloatGuard; |
8
|
|
|
use InputGuard\Guards\InListGuard; |
9
|
|
|
use InputGuard\Guards\InstanceOfGuard; |
10
|
|
|
use InputGuard\Guards\IntGuard; |
11
|
|
|
use InputGuard\Guards\IterableFloatGuard; |
12
|
|
|
use InputGuard\Guards\IterableGuard; |
13
|
|
|
use InputGuard\Guards\IterableIntGuard; |
14
|
|
|
use InputGuard\Guards\IterableStringableGuard; |
15
|
|
|
use InputGuard\Guards\IterableStringGuard; |
16
|
|
|
use InputGuard\Guards\StringableGuard; |
17
|
|
|
use InputGuard\Guards\StringGuard; |
18
|
|
|
|
19
|
|
|
class DefaultConfiguration implements Configuration |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* An array of default values for Valadatable objects that can be overwritten. |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
protected $defaultValues = [ |
27
|
|
|
BoolGuard::class => null, |
28
|
|
|
FloatGuard::class => null, |
29
|
|
|
InListGuard::class => null, |
30
|
|
|
InstanceOfGuard::class => null, |
31
|
|
|
IntGuard::class => null, |
32
|
|
|
IterableFloatGuard::class => null, |
33
|
|
|
IterableIntGuard::class => null, |
34
|
|
|
IterableStringableGuard::class => null, |
35
|
|
|
IterableStringGuard::class => null, |
36
|
|
|
IterableGuard::class => null, |
37
|
|
|
StringableGuard::class => null, |
38
|
|
|
StringGuard::class => null, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
protected $strictTypeComparisionDefault = false; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var bool[] |
48
|
|
|
*/ |
49
|
|
|
protected $strictTypeComparisionOverride = [ |
50
|
|
|
InListGuard::class => true, |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $className |
55
|
|
|
* |
56
|
|
|
* @return mixed |
57
|
|
|
*/ |
58
|
33 |
|
public function defaultValue(string $className) |
59
|
|
|
{ |
60
|
33 |
|
return $this->defaultValues[$className] ?? null; |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function defaultStrict(string $className = ''): bool |
64
|
|
|
{ |
65
|
1 |
|
return $this->strictTypeComparisionOverride[$className] ?? $this->strictTypeComparisionDefault; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|