-
Notifications
You must be signed in to change notification settings - Fork 214
PoC: Configuration\CompositeResolver and SPI discovery #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
507c2b1
b905d69
436598c
1cc833d
e7e3377
cfc5075
179be68
670c45b
a0e7a7e
15e4258
1f255c9
43561b2
40daf2c
a6abd70
df8d847
98b9786
40acb23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\Configuration\Environment\Adapter; | ||
|
|
||
| use function array_diff_key; | ||
| use Composer\InstalledVersions; | ||
| use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\ArrayEnvSource; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\EnvSource; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\EnvSourceProvider; | ||
| use Symfony\Component\Dotenv\Dotenv; | ||
| use Symfony\Component\Dotenv\Exception\PathException; | ||
|
|
||
| #[PackageDependency('symfony/dotenv', '^5.4 || ^6.4 || ^7.0')] | ||
| final class SymfonyDotenvProvider implements EnvSourceProvider | ||
| { | ||
| /** @psalm-suppress UndefinedClass */ | ||
| public function getEnvSource(): EnvSource | ||
|
Check failure on line 20 in src/Config/SDK/Configuration/Environment/Adapter/SymfonyDotenvProvider.php
|
||
| { | ||
| $installPath = InstalledVersions::getRootPackage()['install_path']; | ||
|
|
||
| $backup = [$_SERVER, $_ENV]; | ||
| $env = []; | ||
|
|
||
| try { | ||
| (new Dotenv())->bootEnv($installPath . '/.env'); | ||
| $env = $_SERVER; | ||
| } catch (PathException) { | ||
| } finally { | ||
| [$_SERVER, $_ENV] = $backup; | ||
| } | ||
|
|
||
| return new ArrayEnvSource(array_diff_key($env, $_SERVER)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\Configuration\Environment\Adapter; | ||
|
|
||
| use Composer\InstalledVersions; | ||
| use Dotenv\Dotenv; | ||
| use Dotenv\Exception\InvalidPathException; | ||
| use Nevay\SPI\ServiceProviderDependency\PackageDependency; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\ArrayEnvSource; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\EnvSource; | ||
| use OpenTelemetry\Config\SDK\Configuration\Environment\EnvSourceProvider; | ||
|
|
||
| #[PackageDependency('vlucas/phpdotenv', '^4.0 || ^5.0')] | ||
| final class VlucasPhpdotenvProvider implements EnvSourceProvider | ||
| { | ||
| /** @psalm-suppress UndefinedClass */ | ||
| public function getEnvSource(): EnvSource | ||
|
Check failure on line 19 in src/Config/SDK/Configuration/Environment/Adapter/VlucasPhpdotenvProvider.php
|
||
| { | ||
| $backup = [$_SERVER, $_ENV]; | ||
| $env = []; | ||
|
|
||
| try { | ||
| $env = Dotenv::createImmutable([InstalledVersions::getRootPackage()['install_path']])->load(); | ||
| } catch (InvalidPathException) { | ||
| } finally { | ||
| [$_SERVER, $_ENV] = $backup; | ||
| } | ||
|
|
||
| return new ArrayEnvSource(array_diff_key($env, $_SERVER)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\Configuration\Environment; | ||
|
|
||
| interface EnvSourceProvider | ||
| { | ||
| public function getEnvSource(): EnvSource; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OpenTelemetry\Config\SDK\Configuration\Environment; | ||
|
|
||
| use Closure; | ||
|
|
||
| final class LazyEnvSource implements EnvSource | ||
| { | ||
| /** | ||
| * @param Closure(): EnvSource|EnvSource $env | ||
brettmc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| public function __construct( | ||
| private Closure|EnvSource $env, | ||
| ) { | ||
| } | ||
|
|
||
| public function readRaw(string $name): mixed | ||
|
Check failure on line 19 in src/Config/SDK/Configuration/Environment/LazyEnvSource.php
|
||
| { | ||
| if (!$this->env instanceof EnvSource) { | ||
| $this->env = ($this->env)(); | ||
| } | ||
|
|
||
| return $this->env->readRaw($name); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.