Version 1
[yaffs-website] / vendor / dflydev / dot-access-configuration / src / Dflydev / DotAccessConfiguration / YamlConfigurationBuilder.php
diff --git a/vendor/dflydev/dot-access-configuration/src/Dflydev/DotAccessConfiguration/YamlConfigurationBuilder.php b/vendor/dflydev/dot-access-configuration/src/Dflydev/DotAccessConfiguration/YamlConfigurationBuilder.php
new file mode 100644 (file)
index 0000000..06f2ded
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is a part of dflydev/dot-access-configuration.
+ *
+ * (c) Dragonfly Development Inc.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Dflydev\DotAccessConfiguration;
+
+use Psr\Log\InvalidArgumentException;
+use Symfony\Component\Yaml\Yaml;
+
+class YamlConfigurationBuilder extends AbstractConfigurationBuilder
+{
+    /**
+     * YAML input string
+     *
+     * @var string
+     */
+    protected $input;
+
+    /**
+     * Constructor
+     *
+     * @param string|null $input
+     */
+    public function __construct($input = null)
+    {
+        $this->input = $input;
+    }
+
+    /**
+     * {@inheritdocs}
+     */
+    public function internalBuild(ConfigurationInterface $configuration)
+    {
+        if (null !== $this->input) {
+            try{
+                $yml = Yaml::parse($this->input, true);
+            } catch (\Exception $e) {
+                throw new InvalidArgumentException($e->getMessage(), 0, $e);
+            }
+            if (is_string($yml))
+            {
+                throw(new \InvalidArgumentException('Yaml could not be parsed, parser detected a string.'));
+            }
+            $configuration->importRaw($yml);
+        }
+    }
+}