File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
src/Config/SDK/Configuration/Environment/Adapter Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace OpenTelemetry \Config \SDK \Configuration \Environment \Adapter ;
6+
7+ use Composer \InstalledVersions ;
8+ use Dotenv \Dotenv ;
9+ use Nevay \SPI \ServiceProviderDependency \PackageDependency ;
10+ use OpenTelemetry \Config \SDK \Configuration \Environment \ArrayEnvSource ;
11+ use OpenTelemetry \Config \SDK \Configuration \Environment \EnvSource ;
12+ use OpenTelemetry \Config \SDK \Configuration \Environment \EnvSourceProvider ;
13+ use Symfony \Component \Dotenv \Dotenv ;
14+ use Symfony \Component \Dotenv \Exception \PathException ;
15+ use function array_diff_key ;
16+
17+ #[PackageDependency('symfony/dotenv ' , '^5.4 || ^6.4 || ^7.0 ' )]
18+ final class SymfonyDotenvProvider implements EnvSourceProvider {
19+
20+ public function getEnvSource (): EnvSource {
21+ $ installPath = InstalledVersions::getRootPackage ()['install_path ' ];
22+
23+ $ backup = [$ _SERVER , $ _ENV ];
24+ $ env = [];
25+
26+ try {
27+ (new Dotenv ())->bootEnv ($ installPath . '/.env ' );
28+ $ env = $ _SERVER ;
29+ } catch (PathException ) {
30+ } finally {
31+ [$ _SERVER , $ _ENV ] = $ backup ;
32+ }
33+
34+ return new ArrayEnvSource (array_diff_key ($ env , $ _SERVER ));
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments