ClosureLoader.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. * Constructor.
  25. *
  26. * @param ContainerBuilder $container A ContainerBuilder instance
  27. */
  28. public function __construct(ContainerBuilder $container)
  29. {
  30. $this->container = $container;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function load($resource, $type = null)
  36. {
  37. call_user_func($resource, $this->container);
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function supports($resource, $type = null)
  43. {
  44. return $resource instanceof \Closure;
  45. }
  46. }