|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Web; |
|
6
|
|
|
|
|
7
|
|
|
use InvalidArgumentException; |
|
8
|
|
|
|
|
9
|
|
|
use function array_merge; |
|
10
|
|
|
|
|
11
|
|
|
class ApplicationParameters implements ApplicationParametersInterface |
|
12
|
|
|
{ |
|
13
|
|
|
private array $params = [ |
|
14
|
|
|
'name' => 'My Project', |
|
15
|
|
|
'charset' => 'UTF-8', |
|
16
|
|
|
'language' => 'en', |
|
17
|
|
|
'email' => '[email protected]', |
|
18
|
|
|
'adminEmail' => '[email protected]', |
|
19
|
|
|
'infoEmail' => '[email protected]', |
|
20
|
|
|
'supportEmail' => '[email protected]', |
|
21
|
|
|
]; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(array $params) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->params = array_merge($this->params, $params); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function get(string $name): string |
|
29
|
|
|
{ |
|
30
|
|
|
if (isset($this->params[$name])) { |
|
31
|
|
|
return $this->params[$name]; |
|
32
|
|
|
} |
|
33
|
|
|
throw new InvalidArgumentException('Application Parameter: "' . $name . '" not found.'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function getAdminEmail(): string |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->params['adminEmail']; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getCharset(): string |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->params['charset']; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function getEmail(): string |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->params['email']; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getInfoEmail(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->params['infoEmail']; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getLanguage(): string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->params['language']; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getName(): string |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->params['name']; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getSupportEmail(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->params['supportEmail']; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function has(string $name): bool |
|
73
|
|
|
{ |
|
74
|
|
|
return isset($this->params[$name]); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function with(string $name, $value): self |
|
78
|
|
|
{ |
|
79
|
|
|
$new = clone $this; |
|
80
|
|
|
$new->params[$name] = $value; |
|
81
|
|
|
return $new; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function withAdminEmail(string $value): self |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->with('adminEmail', $value); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function withCharset(string $value): self |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->with('charset', $value); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function withEmail(string $value): self |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->with('email', $value); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function withInfoEmail(string $value): self |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->with('infoEmail', $value); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function withLanguage(string $value): self |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->with('language', $value); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function withName(string $value): self |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->with('name', $value); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function without(string $name): self |
|
115
|
|
|
{ |
|
116
|
|
|
$new = clone $this; |
|
117
|
|
|
unset($new->params[$name]); |
|
118
|
|
|
return $new; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function withSupportEmail(string $value): self |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->with('supportEmail', $value); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|