06f2ded4a488a59df8f9f4b4ed839863e430ad1f
[yaffs-website] / vendor / dflydev / dot-access-configuration / src / Dflydev / DotAccessConfiguration / YamlConfigurationBuilder.php
1 <?php
2
3 /*
4  * This file is a part of dflydev/dot-access-configuration.
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 Dflydev\DotAccessConfiguration;
13
14 use Psr\Log\InvalidArgumentException;
15 use Symfony\Component\Yaml\Yaml;
16
17 class YamlConfigurationBuilder extends AbstractConfigurationBuilder
18 {
19     /**
20      * YAML input string
21      *
22      * @var string
23      */
24     protected $input;
25
26     /**
27      * Constructor
28      *
29      * @param string|null $input
30      */
31     public function __construct($input = null)
32     {
33         $this->input = $input;
34     }
35
36     /**
37      * {@inheritdocs}
38      */
39     public function internalBuild(ConfigurationInterface $configuration)
40     {
41         if (null !== $this->input) {
42             try{
43                 $yml = Yaml::parse($this->input, true);
44             } catch (\Exception $e) {
45                 throw new InvalidArgumentException($e->getMessage(), 0, $e);
46             }
47             if (is_string($yml))
48             {
49                 throw(new \InvalidArgumentException('Yaml could not be parsed, parser detected a string.'));
50             }
51             $configuration->importRaw($yml);
52         }
53     }
54 }