|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is a part of Sculpin. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Dragonfly Development Inc. |
|
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 Symplify\PHP7_Sculpin\Configuration; |
|
13
|
|
|
|
|
14
|
|
|
use Dflydev\DotAccessConfiguration\AbstractConfigurationBuilder; |
|
15
|
|
|
use Dflydev\DotAccessConfiguration\ConfigurationInterface; |
|
16
|
|
|
use Dflydev\DotAccessData\Util as DotAccessDataUtil; |
|
17
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
18
|
|
|
|
|
19
|
|
|
final class YamlFileConfigurationBuilder extends AbstractConfigurationBuilder |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var string[] |
|
23
|
|
|
*/ |
|
24
|
|
|
private $yamlConfigurationFilenames; |
|
25
|
|
|
|
|
26
|
1 |
|
public function __construct(array $yamlConfigurationFilenames) |
|
27
|
|
|
{ |
|
28
|
1 |
|
$this->yamlConfigurationFilenames = $yamlConfigurationFilenames; |
|
29
|
1 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc}. |
|
33
|
|
|
*/ |
|
34
|
1 |
|
public function internalBuild(ConfigurationInterface $configuration) |
|
35
|
|
|
{ |
|
36
|
1 |
|
$config = []; |
|
37
|
1 |
|
$imports = []; |
|
38
|
1 |
|
foreach ($this->yamlConfigurationFilenames as $yamlConfigurationFilename) { |
|
39
|
1 |
|
if (file_exists($yamlConfigurationFilename)) { |
|
40
|
1 |
|
$config = DotAccessDataUtil::mergeAssocArray( |
|
41
|
1 |
|
$config, Yaml::parse(file_get_contents($yamlConfigurationFilename)) |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
1 |
|
if (isset($config['imports'])) { |
|
45
|
|
|
foreach ((array) $config['imports'] as $file) { |
|
46
|
|
|
if (0 === strpos($file, '/')) { |
|
47
|
|
|
// Absolute path |
|
48
|
|
|
$imports[] = $file; |
|
49
|
|
|
} else { |
|
50
|
|
|
if ($realpath = realpath(dirname($yamlConfigurationFilename).'/'.$file)) { |
|
51
|
1 |
|
$imports[] = $realpath; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
if ($imports) { |
|
|
|
|
|
|
60
|
|
|
$importsBuilder = new static($imports); |
|
61
|
|
|
|
|
62
|
|
|
// We want to reconfigure the imports builder to have the |
|
63
|
|
|
// same basic configuration as this instance. |
|
64
|
|
|
$this->reconfigure($importsBuilder); |
|
65
|
|
|
|
|
66
|
|
|
$configuration->import($importsBuilder->build()); |
|
67
|
|
|
|
|
68
|
|
|
$internalImports = $configuration->get('imports'); |
|
69
|
|
|
} else { |
|
70
|
1 |
|
$internalImports = null; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
$configuration->importRaw($config); |
|
74
|
|
|
|
|
75
|
1 |
|
if ($internalImports) { |
|
76
|
|
|
foreach ((array) $internalImports as $import) { |
|
77
|
|
|
$configuration->append('imports', $import); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
1 |
|
return $configuration; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.