本文整理汇总了PHP中Symfony\Component\DependencyInjection\Loader\ClosureLoader类的典型用法代码示例。如果您正苦于以下问题:PHP ClosureLoader类的具体用法?PHP ClosureLoader怎么用?PHP ClosureLoader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClosureLoader类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLoad
public function testLoad()
{
$loader = new ClosureLoader($container = new ContainerBuilder());
$loader->load(function ($container) {
$container->setParameter('foo', 'foo');
});
$this->assertEquals('foo', $container->getParameter('foo'), '->load() loads a \\Closure resource');
}
示例2: testLazyLoadedService
public function testLazyLoadedService()
{
$loader = new ClosureLoader($container = new ContainerBuilder());
$loader->load(function (ContainerBuilder $container) {
$container->set('a', new \BazClass());
$definition = new Definition('BazClass');
$definition->setLazy(true);
$container->setDefinition('a', $definition);
});
$container->setResourceTracking(true);
$container->compile();
$class = new \BazClass();
$reflectionClass = new \ReflectionClass($class);
$r = new \ReflectionProperty($container, 'resources');
$r->setAccessible(true);
$resources = $r->getValue($container);
$classInList = false;
foreach ($resources as $resource) {
if ($resource->getResource() === $reflectionClass->getFileName()) {
$classInList = true;
break;
}
}
$this->assertTrue($classInList);
}
示例3: createContainerFromClosure
protected function createContainerFromClosure($closure, $data = array())
{
$container = $this->createContainer($data);
$container->registerExtension(new FrameworkExtension());
$loader = new ClosureLoader($container);
$loader->load($closure);
$container->getCompilerPassConfig()->setOptimizationPasses(array());
$container->getCompilerPassConfig()->setRemovingPasses(array());
$container->compile();
return $container;
}