summaryrefslogtreecommitdiffstats
path: root/vendor/symfony/config/Symfony/Component/Config/Loader
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/config/Symfony/Component/Config/Loader')
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/DelegatingLoader.php55
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/FileLoader.php124
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/Loader.php78
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/LoaderInterface.php54
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolver.php75
-rw-r--r--vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolverInterface.php30
6 files changed, 416 insertions, 0 deletions
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/DelegatingLoader.php b/vendor/symfony/config/Symfony/Component/Config/Loader/DelegatingLoader.php
new file mode 100644
index 0000000..3097878
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/DelegatingLoader.php
@@ -0,0 +1,55 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * 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\Exception\FileLoaderLoadException;
+
+/**
+ * DelegatingLoader delegates loading to other loaders using a loader resolver.
+ *
+ * This loader acts as an array of LoaderInterface objects - each having
+ * a chance to load a given resource (handled by the resolver)
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class DelegatingLoader extends Loader
+{
+ /**
+ * Constructor.
+ *
+ * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
+ */
+ public function __construct(LoaderResolverInterface $resolver)
+ {
+ $this->resolver = $resolver;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function load($resource, $type = null)
+ {
+ if (false === $loader = $this->resolver->resolve($resource, $type)) {
+ throw new FileLoaderLoadException($resource);
+ }
+
+ return $loader->load($resource, $type);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function supports($resource, $type = null)
+ {
+ return false !== $this->resolver->resolve($resource, $type);
+ }
+}
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/FileLoader.php b/vendor/symfony/config/Symfony/Component/Config/Loader/FileLoader.php
new file mode 100644
index 0000000..21e4c47
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/FileLoader.php
@@ -0,0 +1,124 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * 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\FileLocatorInterface;
+use Symfony\Component\Config\Exception\FileLoaderLoadException;
+use Symfony\Component\Config\Exception\FileLoaderImportCircularReferenceException;
+
+/**
+ * FileLoader is the abstract class used by all built-in loaders that are file based.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+abstract class FileLoader extends Loader
+{
+ /**
+ * @var array
+ */
+ protected static $loading = array();
+
+ /**
+ * @var FileLocatorInterface
+ */
+ protected $locator;
+
+ private $currentDir;
+
+ /**
+ * Constructor.
+ *
+ * @param FileLocatorInterface $locator A FileLocatorInterface instance
+ */
+ public function __construct(FileLocatorInterface $locator)
+ {
+ $this->locator = $locator;
+ }
+
+ /**
+ * Sets the current directory.
+ *
+ * @param string $dir
+ */
+ public function setCurrentDir($dir)
+ {
+ $this->currentDir = $dir;
+ }
+
+ /**
+ * Returns the file locator used by this loader.
+ *
+ * @return FileLocatorInterface
+ */
+ public function getLocator()
+ {
+ return $this->locator;
+ }
+
+ /**
+ * Imports a resource.
+ *
+ * @param mixed $resource A Resource
+ * @param string|null $type The resource type or null if unknown
+ * @param bool $ignoreErrors Whether to ignore import errors or not
+ * @param string|null $sourceResource The original resource importing the new resource
+ *
+ * @return mixed
+ *
+ * @throws FileLoaderLoadException
+ * @throws FileLoaderImportCircularReferenceException
+ */
+ public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
+ {
+ try {
+ $loader = $this->resolve($resource, $type);
+
+ if ($loader instanceof FileLoader && null !== $this->currentDir) {
+ // we fallback to the current locator to keep BC
+ // as some some loaders do not call the parent __construct()
+ // @deprecated should be removed in 3.0
+ $locator = $loader->getLocator() ?: $this->locator;
+ $resource = $locator->locate($resource, $this->currentDir, false);
+ }
+
+ $resources = is_array($resource) ? $resource : array($resource);
+ for ($i = 0; $i < $resourcesCount = count($resources); $i++) {
+ if (isset(self::$loading[$resources[$i]])) {
+ if ($i == $resourcesCount - 1) {
+ throw new FileLoaderImportCircularReferenceException(array_keys(self::$loading));
+ }
+ } else {
+ $resource = $resources[$i];
+ break;
+ }
+ }
+ self::$loading[$resource] = true;
+
+ $ret = $loader->load($resource, $type);
+
+ unset(self::$loading[$resource]);
+
+ return $ret;
+ } catch (FileLoaderImportCircularReferenceException $e) {
+ throw $e;
+ } catch (\Exception $e) {
+ if (!$ignoreErrors) {
+ // prevent embedded imports from nesting multiple exceptions
+ if ($e instanceof FileLoaderLoadException) {
+ throw $e;
+ }
+
+ throw new FileLoaderLoadException($resource, $sourceResource, null, $e);
+ }
+ }
+ }
+}
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/Loader.php b/vendor/symfony/config/Symfony/Component/Config/Loader/Loader.php
new file mode 100644
index 0000000..de4e127
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/Loader.php
@@ -0,0 +1,78 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * 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\Exception\FileLoaderLoadException;
+
+/**
+ * Loader is the abstract class used by all built-in loaders.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+abstract class Loader implements LoaderInterface
+{
+ protected $resolver;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getResolver()
+ {
+ return $this->resolver;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setResolver(LoaderResolverInterface $resolver)
+ {
+ $this->resolver = $resolver;
+ }
+
+ /**
+ * Imports a resource.
+ *
+ * @param mixed $resource A resource
+ * @param string|null $type The resource type or null if unknown
+ *
+ * @return mixed
+ */
+ public function import($resource, $type = null)
+ {
+ return $this->resolve($resource, $type)->load($resource, $type);
+ }
+
+ /**
+ * Finds a loader able to load an imported resource.
+ *
+ * @param mixed $resource A resource
+ * @param string|null $type The resource type or null if unknown
+ *
+ * @return LoaderInterface A LoaderInterface instance
+ *
+ * @throws FileLoaderLoadException If no loader is found
+ */
+ public function resolve($resource, $type = null)
+ {
+ if ($this->supports($resource, $type)) {
+ return $this;
+ }
+
+ $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type);
+
+ if (false === $loader) {
+ throw new FileLoaderLoadException($resource);
+ }
+
+ return $loader;
+ }
+}
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderInterface.php b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderInterface.php
new file mode 100644
index 0000000..dd0a85a
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderInterface.php
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Config\Loader;
+
+/**
+ * LoaderInterface is the interface implemented by all loader classes.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+interface LoaderInterface
+{
+ /**
+ * Loads a resource.
+ *
+ * @param mixed $resource The resource
+ * @param string|null $type The resource type or null if unknown
+ *
+ * @throws \Exception If something went wrong
+ */
+ public function load($resource, $type = null);
+
+ /**
+ * Returns whether this class supports the given resource.
+ *
+ * @param mixed $resource A resource
+ * @param string|null $type The resource type or null if unknown
+ *
+ * @return bool True if this class supports the given resource, false otherwise
+ */
+ public function supports($resource, $type = null);
+
+ /**
+ * Gets the loader resolver.
+ *
+ * @return LoaderResolverInterface A LoaderResolverInterface instance
+ */
+ public function getResolver();
+
+ /**
+ * Sets the loader resolver.
+ *
+ * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
+ */
+ public function setResolver(LoaderResolverInterface $resolver);
+}
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolver.php b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolver.php
new file mode 100644
index 0000000..dc6846d
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolver.php
@@ -0,0 +1,75 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Config\Loader;
+
+/**
+ * LoaderResolver selects a loader for a given resource.
+ *
+ * A resource can be anything (e.g. a full path to a config file or a Closure).
+ * Each loader determines whether it can load a resource and how.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class LoaderResolver implements LoaderResolverInterface
+{
+ /**
+ * @var LoaderInterface[] An array of LoaderInterface objects
+ */
+ private $loaders = array();
+
+ /**
+ * Constructor.
+ *
+ * @param LoaderInterface[] $loaders An array of loaders
+ */
+ public function __construct(array $loaders = array())
+ {
+ foreach ($loaders as $loader) {
+ $this->addLoader($loader);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function resolve($resource, $type = null)
+ {
+ foreach ($this->loaders as $loader) {
+ if ($loader->supports($resource, $type)) {
+ return $loader;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Adds a loader.
+ *
+ * @param LoaderInterface $loader A LoaderInterface instance
+ */
+ public function addLoader(LoaderInterface $loader)
+ {
+ $this->loaders[] = $loader;
+ $loader->setResolver($this);
+ }
+
+ /**
+ * Returns the registered loaders.
+ *
+ * @return LoaderInterface[] An array of LoaderInterface instances
+ */
+ public function getLoaders()
+ {
+ return $this->loaders;
+ }
+}
diff --git a/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolverInterface.php b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolverInterface.php
new file mode 100644
index 0000000..40f1a1a
--- /dev/null
+++ b/vendor/symfony/config/Symfony/Component/Config/Loader/LoaderResolverInterface.php
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Config\Loader;
+
+/**
+ * LoaderResolverInterface selects a loader for a given resource.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+interface LoaderResolverInterface
+{
+ /**
+ * Returns a loader able to load the resource.
+ *
+ * @param mixed $resource A resource
+ * @param string|null $type The resource type or null if unknown
+ *
+ * @return LoaderInterface|false The loader or false if none is able to load the resource
+ */
+ public function resolve($resource, $type = null);
+}