create-berna-stencil 1.0.40 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/_tools/res/templates/template.njk +8 -8
  2. package/_tools/res/templates/template.scss +16 -16
  3. package/package.json +71 -71
  4. package/src/api/core/composer.lock +492 -492
  5. package/src/api/core/vendor/composer/autoload_static.php +10 -10
  6. package/src/api/core/vendor/composer/installed.json +6 -6
  7. package/src/api/core/vendor/composer/installed.php +2 -2
  8. package/src/api/core/vendor/graham-campbell/result-type/.gitattributes +9 -0
  9. package/src/api/core/vendor/graham-campbell/result-type/.github/CODE_OF_CONDUCT.md +132 -0
  10. package/src/api/core/vendor/graham-campbell/result-type/.github/CONTRIBUTING.md +31 -0
  11. package/src/api/core/vendor/graham-campbell/result-type/.github/FUNDING.yml +2 -0
  12. package/src/api/core/vendor/graham-campbell/result-type/.github/SECURITY.md +14 -0
  13. package/src/api/core/vendor/graham-campbell/result-type/.github/workflows/stale.yml +11 -0
  14. package/src/api/core/vendor/graham-campbell/result-type/.github/workflows/tests.yml +40 -0
  15. package/src/api/core/vendor/graham-campbell/result-type/CHANGELOG.md +53 -0
  16. package/src/api/core/vendor/graham-campbell/result-type/LICENSE +21 -21
  17. package/src/api/core/vendor/graham-campbell/result-type/README.md +42 -0
  18. package/src/api/core/vendor/graham-campbell/result-type/composer.json +33 -33
  19. package/src/api/core/vendor/graham-campbell/result-type/phpunit.xml.dist +13 -0
  20. package/src/api/core/vendor/graham-campbell/result-type/src/Error.php +121 -121
  21. package/src/api/core/vendor/graham-campbell/result-type/src/Result.php +69 -69
  22. package/src/api/core/vendor/graham-campbell/result-type/src/Success.php +120 -120
  23. package/src/api/core/vendor/graham-campbell/result-type/tests/ResultTest.php +95 -0
  24. package/src/api/core/vendor/phpoption/phpoption/.gitattributes +13 -0
  25. package/src/api/core/vendor/phpoption/phpoption/.github/CODE_OF_CONDUCT.md +132 -0
  26. package/src/api/core/vendor/phpoption/phpoption/.github/CONTRIBUTING.md +30 -0
  27. package/src/api/core/vendor/phpoption/phpoption/.github/FUNDING.yml +2 -0
  28. package/src/api/core/vendor/phpoption/phpoption/.github/SECURITY.md +14 -0
  29. package/src/api/core/vendor/phpoption/phpoption/.github/workflows/static.yml +40 -0
  30. package/src/api/core/vendor/phpoption/phpoption/.github/workflows/tests.yml +40 -0
  31. package/src/api/core/vendor/phpoption/phpoption/LICENSE +200 -200
  32. package/src/api/core/vendor/phpoption/phpoption/Makefile +17 -0
  33. package/src/api/core/vendor/phpoption/phpoption/README.md +201 -0
  34. package/src/api/core/vendor/phpoption/phpoption/composer.json +50 -50
  35. package/src/api/core/vendor/phpoption/phpoption/phpstan-baseline.neon +44 -0
  36. package/src/api/core/vendor/phpoption/phpoption/phpstan.neon.dist +7 -0
  37. package/src/api/core/vendor/phpoption/phpoption/phpunit.xml.dist +13 -0
  38. package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/LazyOption.php +175 -175
  39. package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/None.php +136 -136
  40. package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/Option.php +434 -434
  41. package/src/api/core/vendor/phpoption/phpoption/src/PhpOption/Some.php +169 -169
  42. package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/EnsureTest.php +72 -0
  43. package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/LazyOptionTest.php +357 -0
  44. package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/NoneTest.php +153 -0
  45. package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/OptionTest.php +166 -0
  46. package/src/api/core/vendor/phpoption/phpoption/tests/PhpOption/Tests/SomeTest.php +194 -0
  47. package/src/api/core/vendor/phpoption/phpoption/tests/bootstrap.php +8 -0
  48. package/src/api/core/vendor/phpoption/phpoption/vendor-bin/phpstan/composer.json +8 -0
  49. package/src/api/core/vendor/symfony/polyfill-ctype/Ctype.php +232 -232
  50. package/src/api/core/vendor/symfony/polyfill-ctype/LICENSE +19 -19
  51. package/src/api/core/vendor/symfony/polyfill-ctype/README.md +12 -12
  52. package/src/api/core/vendor/symfony/polyfill-ctype/bootstrap.php +50 -50
  53. package/src/api/core/vendor/symfony/polyfill-ctype/bootstrap80.php +46 -46
  54. package/src/api/core/vendor/symfony/polyfill-ctype/composer.json +38 -38
  55. package/src/api/core/vendor/symfony/polyfill-mbstring/LICENSE +19 -19
  56. package/src/api/core/vendor/symfony/polyfill-mbstring/Mbstring.php +1077 -1077
  57. package/src/api/core/vendor/symfony/polyfill-mbstring/README.md +13 -13
  58. package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/caseFolding.php +119 -119
  59. package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php +1397 -1397
  60. package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/titleCaseRegexp.php +5 -5
  61. package/src/api/core/vendor/symfony/polyfill-mbstring/Resources/unidata/upperCase.php +1489 -1489
  62. package/src/api/core/vendor/symfony/polyfill-mbstring/bootstrap.php +171 -171
  63. package/src/api/core/vendor/symfony/polyfill-mbstring/bootstrap80.php +167 -167
  64. package/src/api/core/vendor/symfony/polyfill-mbstring/composer.json +39 -39
  65. package/src/api/core/vendor/symfony/polyfill-php80/LICENSE +19 -19
  66. package/src/api/core/vendor/symfony/polyfill-php80/Php80.php +115 -115
  67. package/src/api/core/vendor/symfony/polyfill-php80/PhpToken.php +106 -106
  68. package/src/api/core/vendor/symfony/polyfill-php80/README.md +25 -25
  69. package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/Attribute.php +31 -31
  70. package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/PhpToken.php +16 -16
  71. package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/Stringable.php +20 -20
  72. package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php +16 -16
  73. package/src/api/core/vendor/symfony/polyfill-php80/Resources/stubs/ValueError.php +16 -16
  74. package/src/api/core/vendor/symfony/polyfill-php80/bootstrap.php +42 -42
  75. package/src/api/core/vendor/symfony/polyfill-php80/composer.json +37 -37
  76. package/src/api/core/vendor/vlucas/phpdotenv/.editorconfig +15 -0
  77. package/src/api/core/vendor/vlucas/phpdotenv/.gitattributes +15 -0
  78. package/src/api/core/vendor/vlucas/phpdotenv/.github/CODE_OF_CONDUCT.md +132 -0
  79. package/src/api/core/vendor/vlucas/phpdotenv/.github/CONTRIBUTING.md +30 -0
  80. package/src/api/core/vendor/vlucas/phpdotenv/.github/FUNDING.yml +2 -0
  81. package/src/api/core/vendor/vlucas/phpdotenv/.github/SECURITY.md +14 -0
  82. package/src/api/core/vendor/vlucas/phpdotenv/.github/workflows/static.yml +40 -0
  83. package/src/api/core/vendor/vlucas/phpdotenv/.github/workflows/tests.yml +70 -0
  84. package/src/api/core/vendor/vlucas/phpdotenv/LICENSE +30 -30
  85. package/src/api/core/vendor/vlucas/phpdotenv/Makefile +17 -0
  86. package/src/api/core/vendor/vlucas/phpdotenv/README.md +370 -0
  87. package/src/api/core/vendor/vlucas/phpdotenv/UPGRADING.md +196 -0
  88. package/src/api/core/vendor/vlucas/phpdotenv/composer.json +60 -60
  89. package/src/api/core/vendor/vlucas/phpdotenv/phpstan-baseline.neon +157 -0
  90. package/src/api/core/vendor/vlucas/phpdotenv/phpstan.neon.dist +7 -0
  91. package/src/api/core/vendor/vlucas/phpdotenv/phpunit.xml.dist +13 -0
  92. package/src/api/core/vendor/vlucas/phpdotenv/src/Dotenv.php +267 -267
  93. package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/ExceptionInterface.php +12 -12
  94. package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidEncodingException.php +12 -12
  95. package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidFileException.php +12 -12
  96. package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/InvalidPathException.php +12 -12
  97. package/src/api/core/vendor/vlucas/phpdotenv/src/Exception/ValidationException.php +12 -12
  98. package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/Loader.php +48 -48
  99. package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/LoaderInterface.php +20 -20
  100. package/src/api/core/vendor/vlucas/phpdotenv/src/Loader/Resolver.php +65 -65
  101. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Entry.php +59 -59
  102. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/EntryParser.php +299 -299
  103. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Lexer.php +58 -58
  104. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Lines.php +127 -127
  105. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Parser.php +53 -53
  106. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/ParserInterface.php +19 -19
  107. package/src/api/core/vendor/vlucas/phpdotenv/src/Parser/Value.php +88 -88
  108. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/AdapterInterface.php +15 -15
  109. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ApacheAdapter.php +89 -89
  110. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ArrayAdapter.php +80 -80
  111. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/EnvConstAdapter.php +88 -88
  112. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/GuardedWriter.php +85 -85
  113. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ImmutableWriter.php +110 -110
  114. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiReader.php +48 -48
  115. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/MultiWriter.php +64 -64
  116. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/PutenvAdapter.php +91 -91
  117. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReaderInterface.php +17 -17
  118. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ReplacingWriter.php +104 -104
  119. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/ServerConstAdapter.php +88 -88
  120. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/Adapter/WriterInterface.php +27 -27
  121. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/AdapterRepository.php +107 -107
  122. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/RepositoryBuilder.php +272 -272
  123. package/src/api/core/vendor/vlucas/phpdotenv/src/Repository/RepositoryInterface.php +51 -51
  124. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/File/Paths.php +44 -44
  125. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/File/Reader.php +81 -81
  126. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/FileStore.php +72 -72
  127. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StoreBuilder.php +141 -141
  128. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StoreInterface.php +17 -17
  129. package/src/api/core/vendor/vlucas/phpdotenv/src/Store/StringStore.php +37 -37
  130. package/src/api/core/vendor/vlucas/phpdotenv/src/Util/Regex.php +112 -112
  131. package/src/api/core/vendor/vlucas/phpdotenv/src/Util/Str.php +108 -108
  132. package/src/api/core/vendor/vlucas/phpdotenv/src/Validator.php +207 -207
  133. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/DotenvTest.php +387 -0
  134. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Loader/LoaderTest.php +86 -0
  135. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/EntryParserTest.php +234 -0
  136. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/LexerTest.php +40 -0
  137. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/LinesTest.php +53 -0
  138. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Parser/ParserTest.php +98 -0
  139. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/ArrayAdapterTest.php +57 -0
  140. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/EnvConstAdapterTest.php +75 -0
  141. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/PutenvAdapterTest.php +52 -0
  142. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/Adapter/ServerConstAdapterTest.php +75 -0
  143. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Repository/RepositoryTest.php +305 -0
  144. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/Store/StoreTest.php +141 -0
  145. package/src/api/core/vendor/vlucas/phpdotenv/tests/Dotenv/ValidatorTest.php +479 -0
  146. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/.env +5 -0
  147. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/assertions.env +18 -0
  148. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/booleans.env +33 -0
  149. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/commented.env +15 -0
  150. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/empty.env +1 -0
  151. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/example.env +1 -0
  152. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/exported.env +7 -0
  153. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/immutable.env +1 -0
  154. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/integers.env +17 -0
  155. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/large.env +2 -0
  156. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multibyte.env +3 -0
  157. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multiline.env +14 -0
  158. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/multiple.env +4 -0
  159. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/mutable.env +1 -0
  160. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/nested.env +15 -0
  161. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/quoted.env +11 -0
  162. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/specialchars.env +8 -0
  163. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/unicodevarnames.env +2 -0
  164. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/utf8-with-bom-encoding.env +3 -0
  165. package/src/api/core/vendor/vlucas/phpdotenv/tests/fixtures/env/windows.env +1 -0
  166. package/src/api/core/vendor/vlucas/phpdotenv/vendor-bin/phpstan/composer.json +15 -0
  167. package/src/api/endpoints/protected/example-protected.php +1 -1
  168. package/src/components/layouts/includes.njk +3 -3
  169. package/src/data/site.json +53 -53
  170. package/src/scss/modules/_buttons.scss +2 -2
  171. package/src/scss/modules/_footer.scss +1 -1
  172. package/src/scss/modules/_header.scss +1 -1
@@ -1,207 +1,207 @@
1
- <?php
2
-
3
- declare(strict_types=1);
4
-
5
- namespace Dotenv;
6
-
7
- use Dotenv\Exception\ValidationException;
8
- use Dotenv\Repository\RepositoryInterface;
9
- use Dotenv\Util\Regex;
10
- use Dotenv\Util\Str;
11
-
12
- class Validator
13
- {
14
- /**
15
- * The environment repository instance.
16
- *
17
- * @var \Dotenv\Repository\RepositoryInterface
18
- */
19
- private $repository;
20
-
21
- /**
22
- * The variables to validate.
23
- *
24
- * @var string[]
25
- */
26
- private $variables;
27
-
28
- /**
29
- * Create a new validator instance.
30
- *
31
- * @param \Dotenv\Repository\RepositoryInterface $repository
32
- * @param string[] $variables
33
- *
34
- * @return void
35
- */
36
- public function __construct(RepositoryInterface $repository, array $variables)
37
- {
38
- $this->repository = $repository;
39
- $this->variables = $variables;
40
- }
41
-
42
- /**
43
- * Assert that each variable is present.
44
- *
45
- * @throws \Dotenv\Exception\ValidationException
46
- *
47
- * @return \Dotenv\Validator
48
- */
49
- public function required()
50
- {
51
- return $this->assert(
52
- static function (?string $value) {
53
- return $value !== null;
54
- },
55
- 'is missing'
56
- );
57
- }
58
-
59
- /**
60
- * Assert that each variable is not empty.
61
- *
62
- * @throws \Dotenv\Exception\ValidationException
63
- *
64
- * @return \Dotenv\Validator
65
- */
66
- public function notEmpty()
67
- {
68
- return $this->assertNullable(
69
- static function (string $value) {
70
- return Str::len(\trim($value)) > 0;
71
- },
72
- 'is empty'
73
- );
74
- }
75
-
76
- /**
77
- * Assert that each specified variable is an integer.
78
- *
79
- * @throws \Dotenv\Exception\ValidationException
80
- *
81
- * @return \Dotenv\Validator
82
- */
83
- public function isInteger()
84
- {
85
- return $this->assertNullable(
86
- static function (string $value) {
87
- return \ctype_digit($value);
88
- },
89
- 'is not an integer'
90
- );
91
- }
92
-
93
- /**
94
- * Assert that each specified variable is a boolean.
95
- *
96
- * @throws \Dotenv\Exception\ValidationException
97
- *
98
- * @return \Dotenv\Validator
99
- */
100
- public function isBoolean()
101
- {
102
- return $this->assertNullable(
103
- static function (string $value) {
104
- if ($value === '') {
105
- return false;
106
- }
107
-
108
- return \filter_var($value, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE) !== null;
109
- },
110
- 'is not a boolean'
111
- );
112
- }
113
-
114
- /**
115
- * Assert that each variable is amongst the given choices.
116
- *
117
- * @param string[] $choices
118
- *
119
- * @throws \Dotenv\Exception\ValidationException
120
- *
121
- * @return \Dotenv\Validator
122
- */
123
- public function allowedValues(array $choices)
124
- {
125
- return $this->assertNullable(
126
- static function (string $value) use ($choices) {
127
- return \in_array($value, $choices, true);
128
- },
129
- \sprintf('is not one of [%s]', \implode(', ', $choices))
130
- );
131
- }
132
-
133
- /**
134
- * Assert that each variable matches the given regular expression.
135
- *
136
- * @param string $regex
137
- *
138
- * @throws \Dotenv\Exception\ValidationException
139
- *
140
- * @return \Dotenv\Validator
141
- */
142
- public function allowedRegexValues(string $regex)
143
- {
144
- return $this->assertNullable(
145
- static function (string $value) use ($regex) {
146
- return Regex::matches($regex, $value)->success()->getOrElse(false);
147
- },
148
- \sprintf('does not match "%s"', $regex)
149
- );
150
- }
151
-
152
- /**
153
- * Assert that the callback returns true for each variable.
154
- *
155
- * @param callable(?string):bool $callback
156
- * @param string $message
157
- *
158
- * @throws \Dotenv\Exception\ValidationException
159
- *
160
- * @return \Dotenv\Validator
161
- */
162
- public function assert(callable $callback, string $message)
163
- {
164
- $failing = [];
165
-
166
- foreach ($this->variables as $variable) {
167
- if ($callback($this->repository->get($variable)) === false) {
168
- $failing[] = \sprintf('%s %s', $variable, $message);
169
- }
170
- }
171
-
172
- if (\count($failing) > 0) {
173
- throw new ValidationException(\sprintf(
174
- 'One or more environment variables failed assertions: %s.',
175
- \implode(', ', $failing)
176
- ));
177
- }
178
-
179
- return $this;
180
- }
181
-
182
- /**
183
- * Assert that the callback returns true for each variable.
184
- *
185
- * Skip checking null variable values.
186
- *
187
- * @param callable(string):bool $callback
188
- * @param string $message
189
- *
190
- * @throws \Dotenv\Exception\ValidationException
191
- *
192
- * @return \Dotenv\Validator
193
- */
194
- public function assertNullable(callable $callback, string $message)
195
- {
196
- return $this->assert(
197
- static function (?string $value) use ($callback) {
198
- if ($value === null) {
199
- return true;
200
- }
201
-
202
- return $callback($value);
203
- },
204
- $message
205
- );
206
- }
207
- }
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ namespace Dotenv;
6
+
7
+ use Dotenv\Exception\ValidationException;
8
+ use Dotenv\Repository\RepositoryInterface;
9
+ use Dotenv\Util\Regex;
10
+ use Dotenv\Util\Str;
11
+
12
+ class Validator
13
+ {
14
+ /**
15
+ * The environment repository instance.
16
+ *
17
+ * @var \Dotenv\Repository\RepositoryInterface
18
+ */
19
+ private $repository;
20
+
21
+ /**
22
+ * The variables to validate.
23
+ *
24
+ * @var string[]
25
+ */
26
+ private $variables;
27
+
28
+ /**
29
+ * Create a new validator instance.
30
+ *
31
+ * @param \Dotenv\Repository\RepositoryInterface $repository
32
+ * @param string[] $variables
33
+ *
34
+ * @return void
35
+ */
36
+ public function __construct(RepositoryInterface $repository, array $variables)
37
+ {
38
+ $this->repository = $repository;
39
+ $this->variables = $variables;
40
+ }
41
+
42
+ /**
43
+ * Assert that each variable is present.
44
+ *
45
+ * @throws \Dotenv\Exception\ValidationException
46
+ *
47
+ * @return \Dotenv\Validator
48
+ */
49
+ public function required()
50
+ {
51
+ return $this->assert(
52
+ static function (?string $value) {
53
+ return $value !== null;
54
+ },
55
+ 'is missing'
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Assert that each variable is not empty.
61
+ *
62
+ * @throws \Dotenv\Exception\ValidationException
63
+ *
64
+ * @return \Dotenv\Validator
65
+ */
66
+ public function notEmpty()
67
+ {
68
+ return $this->assertNullable(
69
+ static function (string $value) {
70
+ return Str::len(\trim($value)) > 0;
71
+ },
72
+ 'is empty'
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Assert that each specified variable is an integer.
78
+ *
79
+ * @throws \Dotenv\Exception\ValidationException
80
+ *
81
+ * @return \Dotenv\Validator
82
+ */
83
+ public function isInteger()
84
+ {
85
+ return $this->assertNullable(
86
+ static function (string $value) {
87
+ return \ctype_digit($value);
88
+ },
89
+ 'is not an integer'
90
+ );
91
+ }
92
+
93
+ /**
94
+ * Assert that each specified variable is a boolean.
95
+ *
96
+ * @throws \Dotenv\Exception\ValidationException
97
+ *
98
+ * @return \Dotenv\Validator
99
+ */
100
+ public function isBoolean()
101
+ {
102
+ return $this->assertNullable(
103
+ static function (string $value) {
104
+ if ($value === '') {
105
+ return false;
106
+ }
107
+
108
+ return \filter_var($value, \FILTER_VALIDATE_BOOLEAN, \FILTER_NULL_ON_FAILURE) !== null;
109
+ },
110
+ 'is not a boolean'
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Assert that each variable is amongst the given choices.
116
+ *
117
+ * @param string[] $choices
118
+ *
119
+ * @throws \Dotenv\Exception\ValidationException
120
+ *
121
+ * @return \Dotenv\Validator
122
+ */
123
+ public function allowedValues(array $choices)
124
+ {
125
+ return $this->assertNullable(
126
+ static function (string $value) use ($choices) {
127
+ return \in_array($value, $choices, true);
128
+ },
129
+ \sprintf('is not one of [%s]', \implode(', ', $choices))
130
+ );
131
+ }
132
+
133
+ /**
134
+ * Assert that each variable matches the given regular expression.
135
+ *
136
+ * @param string $regex
137
+ *
138
+ * @throws \Dotenv\Exception\ValidationException
139
+ *
140
+ * @return \Dotenv\Validator
141
+ */
142
+ public function allowedRegexValues(string $regex)
143
+ {
144
+ return $this->assertNullable(
145
+ static function (string $value) use ($regex) {
146
+ return Regex::matches($regex, $value)->success()->getOrElse(false);
147
+ },
148
+ \sprintf('does not match "%s"', $regex)
149
+ );
150
+ }
151
+
152
+ /**
153
+ * Assert that the callback returns true for each variable.
154
+ *
155
+ * @param callable(?string):bool $callback
156
+ * @param string $message
157
+ *
158
+ * @throws \Dotenv\Exception\ValidationException
159
+ *
160
+ * @return \Dotenv\Validator
161
+ */
162
+ public function assert(callable $callback, string $message)
163
+ {
164
+ $failing = [];
165
+
166
+ foreach ($this->variables as $variable) {
167
+ if ($callback($this->repository->get($variable)) === false) {
168
+ $failing[] = \sprintf('%s %s', $variable, $message);
169
+ }
170
+ }
171
+
172
+ if (\count($failing) > 0) {
173
+ throw new ValidationException(\sprintf(
174
+ 'One or more environment variables failed assertions: %s.',
175
+ \implode(', ', $failing)
176
+ ));
177
+ }
178
+
179
+ return $this;
180
+ }
181
+
182
+ /**
183
+ * Assert that the callback returns true for each variable.
184
+ *
185
+ * Skip checking null variable values.
186
+ *
187
+ * @param callable(string):bool $callback
188
+ * @param string $message
189
+ *
190
+ * @throws \Dotenv\Exception\ValidationException
191
+ *
192
+ * @return \Dotenv\Validator
193
+ */
194
+ public function assertNullable(callable $callback, string $message)
195
+ {
196
+ return $this->assert(
197
+ static function (?string $value) use ($callback) {
198
+ if ($value === null) {
199
+ return true;
200
+ }
201
+
202
+ return $callback($value);
203
+ },
204
+ $message
205
+ );
206
+ }
207
+ }