DelegatingLoader.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public function __construct(LoaderResolverInterface $resolver)
  23. {
  24. $this->resolver = $resolver;
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function load($resource, $type = null)
  30. {
  31. if (false === $loader = $this->resolver->resolve($resource, $type)) {
  32. throw new FileLoaderLoadException($resource);
  33. }
  34. return $loader->load($resource, $type);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function supports($resource, $type = null)
  40. {
  41. return false !== $this->resolver->resolve($resource, $type);
  42. }
  43. }