This repository has been archived on 2025-01-19. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
drupalcampbristol/vendor/dflydev/dot-access-configuration/src/Dflydev/DotAccessConfiguration/YamlConfigurationBuilder.php
2018-11-23 12:29:20 +00:00

54 lines
1.3 KiB
PHP

<?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, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE);
} 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);
}
}
}