DelegatingLoader.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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\LoaderLoadException;
  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, string $type = null)
  30. {
  31. if (false === $loader = $this->resolver->resolve($resource, $type)) {
  32. throw new LoaderLoadException($resource, null, 0, null, $type);
  33. }
  34. return $loader->load($resource, $type);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function supports($resource, string $type = null)
  40. {
  41. return false !== $this->resolver->resolve($resource, $type);
  42. }
  43. }