-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.php
57 lines (52 loc) · 1.87 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php declare(strict_types=1);
namespace Nevay\OTelSDK\Configuration;
use Exception;
use Nevay\OTelSDK\Configuration\Config\OpenTelemetryConfiguration;
use Nevay\OTelSDK\Configuration\Environment\EnvSourceReader;
use Nevay\OTelSDK\Configuration\Environment\PhpIniEnvSource;
use Nevay\OTelSDK\Configuration\Environment\ServerEnvSource;
use Nevay\SPI\ServiceLoader;
final class Config {
/**
* Loads SDK components from a configuration file.
*
* Requires either `symfony/yaml` or `ext-yaml`.
*
* @param string|array $configFile config file(s) to load
* @param string|null $cacheFile optional file to cache configuration to
* @param bool $debug whether debug mode is enabled, enables checking of resources for cache
* freshness
* @param Context $context context used for creation
* @return ConfigurationResult created SDK components
* @throws Exception if the configuration is invalid
*/
public static function loadFile(
string|array $configFile,
?string $cacheFile = null,
bool $debug = true,
Context $context = new Context(),
): ConfigurationResult {
return self::factory()
->parseFile($configFile, $cacheFile, $debug)
->create($context);
}
public static function load(
array $config,
Context $context = new Context(),
): ConfigurationResult {
return self::factory()
->process([$config])
->create($context);
}
private static function factory(): ConfigurationFactory {
static $factory;
return $factory ??= new ConfigurationFactory(
ServiceLoader::load(ComponentProvider::class),
new OpenTelemetryConfiguration(),
new EnvSourceReader([
new ServerEnvSource(),
new PhpIniEnvSource(),
]),
);
}
}