Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DependencyInjection\Loader; Chris@0: Chris@17: use Symfony\Component\Config\Loader\Loader; Chris@0: use Symfony\Component\DependencyInjection\ContainerBuilder; Chris@0: Chris@0: /** Chris@0: * ClosureLoader loads service definitions from a PHP closure. Chris@0: * Chris@0: * The Closure has access to the container as its first argument. Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class ClosureLoader extends Loader Chris@0: { Chris@0: private $container; Chris@0: Chris@0: public function __construct(ContainerBuilder $container) Chris@0: { Chris@0: $this->container = $container; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function load($resource, $type = null) Chris@0: { Chris@17: \call_user_func($resource, $this->container); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function supports($resource, $type = null) Chris@0: { Chris@0: return $resource instanceof \Closure; Chris@0: } Chris@0: }