DelegatingLoader.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. * Loads a resource.
  33. *
  34. * @param mixed $resource A resource
  35. * @param string $type The resource type
  36. *
  37. * @return mixed
  38. *
  39. * @throws FileLoaderLoadException if no loader is found.
  40. */
  41. public function load($resource, $type = null)
  42. {
  43. if (false === $loader = $this->resolver->resolve($resource, $type)) {
  44. throw new FileLoaderLoadException($resource);
  45. }
  46. return $loader->load($resource, $type);
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function supports($resource, $type = null)
  52. {
  53. return false === $this->resolver->resolve($resource, $type) ? false : true;
  54. }
  55. }