Drupal investigation

ClosureLoader.php 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\DependencyInjection\Loader;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\Config\Loader\Loader;
  13. /**
  14. * ClosureLoader loads service definitions from a PHP closure.
  15. *
  16. * The Closure has access to the container as its first argument.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. */
  20. class ClosureLoader extends Loader
  21. {
  22. private $container;
  23. /**
  24. * @param ContainerBuilder $container A ContainerBuilder instance
  25. */
  26. public function __construct(ContainerBuilder $container)
  27. {
  28. $this->container = $container;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function load($resource, $type = null)
  34. {
  35. call_user_func($resource, $this->container);
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function supports($resource, $type = null)
  41. {
  42. return $resource instanceof \Closure;
  43. }
  44. }