From b67133a834f1b868b75ba5403e0d2f70c95faf38 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 27 Dec 2016 17:20:48 +0000 Subject: [PATCH] [Config] Add ConfigurableArrayLoader --- .../Config/Loader/ConfigurableArrayLoader.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/Symfony/Component/Config/Loader/ConfigurableArrayLoader.php diff --git a/src/Symfony/Component/Config/Loader/ConfigurableArrayLoader.php b/src/Symfony/Component/Config/Loader/ConfigurableArrayLoader.php new file mode 100644 index 0000000000000..41321dfd1d3b6 --- /dev/null +++ b/src/Symfony/Component/Config/Loader/ConfigurableArrayLoader.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Config\Loader; + +use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; +use Symfony\Component\Config\Definition\Processor; +use Symfony\Component\Config\Exception\FileLoaderLoadException; + +/** + * @author Roland Franssen + */ +abstract class ConfigurableArrayLoader extends Loader +{ + private $configuration; + + public function __construct(ConfigurationInterface $configuration) + { + $this->configuration = $configuration; + } + + /** + * {@inheritdoc} + */ + public function load($resource, $type = null) + { + $processor = new Processor(); + try { + $config = $processor->processConfiguration($this->configuration, array($resource)); + } catch (InvalidConfigurationException $e) { + throw new FileLoaderLoadException($resource, null, null, $e); + } + + $this->loadConfiguration($config); + } + + abstract protected function loadConfiguration(array $config); + + /** + * {@inheritdoc} + */ + public function supports($resource, $type = null) + { + return is_array($resource); + } +}