Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd18d383

Browse files
committed
[DependencyInjection] Addshuffle env processor
1 parentd1d6126 commitd18d383

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add argument`&$asGhostObject` to LazyProxy's`DumperInterface` to allow using ghost objects for lazy loading services
88
* Add`enum` env var processor
9+
* Add`shuffle` env var processor
910

1011
6.1
1112
---

‎src/Symfony/Component/DependencyInjection/EnvVarProcessor.php‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public static function getProvidedTypes(): array
5858
'trim' =>'string',
5959
'require' =>'bool|int|float|string|array',
6060
'enum' => \BackedEnum::class,
61+
'shuffle' =>'array',
6162
];
6263
}
6364

@@ -82,7 +83,7 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
8283
}
8384

8485
if (!isset($array[$key]) && !\array_key_exists($key,$array)) {
85-
thrownewEnvNotFoundException(sprintf('Key "%s" not found in%s (resolved from "%s").',$key,json_encode($array),$next));
86+
thrownewEnvNotFoundException(sprintf('Key "%s" not found in"%s" (resolved from "%s").',$key,json_encode($array),$next));
8687
}
8788

8889
return$array[$key];
@@ -206,6 +207,12 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed
206207
returnnull;
207208
}
208209

210+
if ('shuffle' ===$prefix) {
211+
shuffle($env);
212+
213+
return$env;
214+
}
215+
209216
if (!\is_scalar($env)) {
210217
thrownewRuntimeException(sprintf('Non-scalar env var "%s" cannot be cast to "%s".',$name,$prefix));
211218
}

‎src/Symfony/Component/DependencyInjection/Tests/EnvVarProcessorTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,16 @@ public function testGetEnvCsv($value, $processed)
708708
$this->assertSame($processed,$result);
709709
}
710710

711+
publicfunctiontestGetEnvShuffle()
712+
{
713+
mt_srand(2);
714+
715+
$this->assertSame(
716+
['bar','foo'],
717+
(newEnvVarProcessor(newContainer()))->getEnv('shuffle','',fn () => ['foo','bar']),
718+
);
719+
}
720+
711721
publicfunctionvalidCsv()
712722
{
713723
$complex = <<<'CSV'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp