DelegatingLoader.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Loader;
  11. use Symfony\Component\Config\Exception\FileLoaderLoadException;
  12. /**
  13. * DelegatingLoader delegates loading to other loaders using a loader resolver.
  14. *
  15. * This loader acts as an array of LoaderInterface objects - each having
  16. * a chance to load a given resource (handled by the resolver)
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class DelegatingLoader extends Loader
  21. {
  22. /**
  23. * Constructor.
  24. *
  25. * @param LoaderResolverInterface $resolver A LoaderResolverInterface instance
  26. */
  27. public function __construct(LoaderResolverInterface $resolver)
  28. {
  29. $this->resolver = $resolver;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function load($resource, $type = null)
  35. {
  36. if (false === $loader = $this->resolver->resolve($resource, $type)) {
  37. throw new FileLoaderLoadException($resource);
  38. }
  39. return $loader->load($resource, $type);
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function supports($resource, $type = null)
  45. {
  46. return false !== $this->resolver->resolve($resource, $type);
  47. }
  48. }