File tree 2 files changed +80
-0
lines changed
src/Symfony/Bundle/FrameworkBundle
2 files changed +80
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Secrets ;
13
+
14
+ use Symfony \Component \DependencyInjection \Attribute \AsDecorator ;
15
+ use Symfony \Component \DependencyInjection \Attribute \AutowireDecorated ;
16
+ use Symfony \Component \DependencyInjection \EnvVarLoaderInterface ;
17
+
18
+ /**
19
+ * @internal
20
+ */
21
+ #[AsDecorator('secrets.vault ' )]
22
+ class StaticEnvVarLoader implements EnvVarLoaderInterface
23
+ {
24
+ private array $ envCache = [];
25
+
26
+ public function __construct (
27
+ #[AutowireDecorated]
28
+ private EnvVarLoaderInterface $ envVarLoader ,
29
+ ) {
30
+ }
31
+
32
+ public function loadEnvVars (): array
33
+ {
34
+ if ([] !== $ this ->envCache ) {
35
+ return $ this ->envCache ;
36
+ }
37
+
38
+ return $ this ->envCache = $ this ->envVarLoader ->loadEnvVars ();
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <fabien@symfony.com>
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \Bundle \FrameworkBundle \Tests \Secrets ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Bundle \FrameworkBundle \Secrets \StaticEnvVarLoader ;
16
+ use Symfony \Component \DependencyInjection \EnvVarLoaderInterface ;
17
+
18
+ class StaticEnvVarLoaderTest extends TestCase
19
+ {
20
+ public function testLoadEnvVarsCachesInnerLoaderEnvVars ()
21
+ {
22
+ $ innerLoader = new class (['FOO ' => 'BAR ' ]) implements EnvVarLoaderInterface {
23
+ /** @param array<string, string> */
24
+ public function __construct (public array $ envVars = [])
25
+ {
26
+ }
27
+
28
+ public function loadEnvVars (): array
29
+ {
30
+ return $ this ->envVars ;
31
+ }
32
+ };
33
+
34
+ $ loader = new StaticEnvVarLoader ($ innerLoader );
35
+ $ this ->assertSame (['FOO ' => 'BAR ' ], $ loader ->loadEnvVars ());
36
+
37
+ $ innerLoader ->envVars = ['BAR ' => 'BAZ ' ];
38
+ $ this ->assertSame (['FOO ' => 'BAR ' ], $ loader ->loadEnvVars ());
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments