-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathConfiguration.php
More file actions
47 lines (36 loc) · 1.08 KB
/
Configuration.php
File metadata and controls
47 lines (36 loc) · 1.08 KB
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
<?php
declare(strict_types=1);
namespace PHPCensor;
use PHPCensor\Common\ParameterBag;
use Symfony\Component\Yaml\Parser as YamlParser;
use PHPCensor\Common\Application\ConfigurationInterface;
/**
* @package PHP Censor
* @subpackage Application
*
* @author Dmitry Khomutov <[email protected]>
*/
class Configuration extends ParameterBag implements ConfigurationInterface
{
private string $configurationPath;
public function __construct(string $configurationPath)
{
parent::__construct([]);
$this->configurationPath = $configurationPath;
$this->load();
}
public function load(): void
{
$parameters = [];
if ($this->configurationPath && \file_exists($this->configurationPath)) {
$parameters = $this->loadYaml($this->configurationPath);
}
$this->parameters = $parameters;
}
private function loadYaml(string $configurationPath): array
{
$parser = new YamlParser();
$yaml = \file_get_contents($configurationPath);
return (array)$parser->parse($yaml);
}
}