本文整理汇总了PHP中Symfony\Component\DependencyInjection\ContainerBuilder::addScope方法的典型用法代码示例。如果您正苦于以下问题:PHP ContainerBuilder::addScope方法的具体用法?PHP ContainerBuilder::addScope怎么用?PHP ContainerBuilder::addScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\ContainerBuilder
的用法示例。
在下文中一共展示了ContainerBuilder::addScope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
if (!class_exists('Assetic\\AssetManager')) {
$this->markTestSkipped('Assetic is not available.');
}
if (!class_exists('Twig_Environment')) {
$this->markTestSkipped('Twig is not available.');
}
$this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock();
$this->container = new ContainerBuilder();
// Symfony 2.3 BC
if (!method_exists('Symfony\\Component\\DependencyInjection\\Definition', 'setShared')) {
$this->container->addScope(new Scope('request'));
$this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
}
// Symfony <2.7 BC
if (class_exists('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper')) {
$this->container->register('assets.packages', $this->getMockClass('Symfony\\Component\\Asset\\Packages'));
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper'))->addArgument(new Reference('assets.packages'));
} elseif (class_exists('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')) {
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\Asset\\PackageInterface')));
}
$this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
$this->container->register('twig', 'Twig_Environment')->addArgument(new Definition($this->getMockClass('Twig_LoaderInterface')));
$this->container->setParameter('kernel.bundles', array());
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('kernel.charset', 'UTF-8');
$this->container->set('kernel', $this->kernel);
$this->container->addCompilerPass(new StaticAsseticHelperPass());
}
示例2: testProcessDetectsCrossScopeHierarchyReference
/**
* @expectedException \RuntimeException
* @group legacy
*/
public function testProcessDetectsCrossScopeHierarchyReference()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('a'));
$container->addScope(new Scope('b'));
$container->register('a')->setScope('a')->addArgument(new Reference('b'));
$container->register('b')->setScope('b');
$this->process($container);
}
示例3: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
$this->container = new ContainerBuilder();
$this->container->addScope(new Scope('request'));
$this->container->setParameter('templating.engines', array('php', 'twig'));
$this->container->set('request', $this->requestMock);
$this->container->registerExtension(new IvoryGoogleMapExtension());
$this->container->registerExtension($httpAdapterExtension = new WidopHttpAdapterExtension());
$this->container->loadFromExtension($httpAdapterExtension->getAlias());
}
示例4: setUp
protected function setUp()
{
$this->kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
$this->container = new ContainerBuilder();
$this->container->addScope(new Scope('request'));
$this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
$this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
$this->container->register('twig', 'Twig_Environment');
$this->container->setParameter('kernel.bundles', array());
$this->container->setParameter('kernel.cache_dir', __DIR__);
$this->container->setParameter('webroot', __DIR__);
$this->container->setParameter('kernel.debug', false);
$this->container->setParameter('kernel.root_dir', __DIR__);
$this->container->setParameter('kernel.charset', 'UTF-8');
$this->container->set('kernel', $this->kernel);
}
开发者ID:platinumpixs,项目名称:symfony2-google-closure-library,代码行数:17,代码来源:PlatinumPixsGoogleClosureLibraryExtensionTest.php
示例5: testWithoutRequestScope
/**
* Tests the onKernelController method without a request scope.
*/
public function testWithoutRequestScope()
{
$this->container->addScope(new Scope(ContaoCoreBundle::SCOPE_BACKEND, 'request'));
/** @var HttpKernelInterface $kernel */
$kernel = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Kernel', ['test', false]);
$listener = new ContainerScopeListener($this->container);
$listener->onKernelRequest(new GetResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST));
$this->assertTrue($this->container->hasScope(ContaoCoreBundle::SCOPE_BACKEND));
$this->assertFalse($this->container->isScopeActive(ContaoCoreBundle::SCOPE_BACKEND));
}
示例6: testBoot
/**
* Tests the boot() method.
*/
public function testBoot()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$bundle = new ContaoCoreBundle();
$bundle->setContainer($container);
$bundle->boot();
$this->assertTrue($container->hasScope(ContaoCoreBundle::SCOPE_BACKEND));
$this->assertTrue($container->hasScope(ContaoCoreBundle::SCOPE_FRONTEND));
}
示例7: testProcessInlinesOnlyIfSameScope
public function testProcessInlinesOnlyIfSameScope()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('foo'));
$a = $container->register('a')->setPublic(false)->setScope('foo');
$b = $container->register('b')->addArgument(new Reference('a'));
$this->process($container);
$arguments = $b->getArguments();
$this->assertEquals(new Reference('a'), $arguments[0]);
$this->assertTrue($container->hasDefinition('a'));
}
示例8: createContainerMock
protected function createContainerMock($render)
{
$templatingMock = $this->getMockBuilder('Symfony\\Bundle\\TwigBundle\\TwigEngine')->disableOriginalConstructor()->getMock();
$templatingMock->expects($this->exactly($render))->method('render');
$container = new ContainerBuilder();
$container->set('templating', $templatingMock);
$container->addScope(new Scope('request'));
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$container->enterScope('request');
return $container;
}
示例9: createContainerMock
protected function createContainerMock()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$container->enterScope('request');
$container->set('templating', $this->createTemplatingMock());
$container->set('router', $this->createRouterMock());
$container->setParameter('thrace_media.jwplayer.options', array('key' => '123', 'html5player' => 'path_to_file', 'flashplayer' => 'path_to_file'));
return $container;
}
示例10: getContainer
private function getContainer()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->set('request', $this->request);
$container->set('templating', $this->templating);
$container->setParameter('kernel.bundles', array());
$container->setParameter('kernel.cache_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->set('kernel', $this->kernel);
return $container;
}
示例11: getContainerBuilder
protected function getContainerBuilder()
{
// \sys_get_temp_dir()
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$container->setParameter('kernel.debug', false);
$container->setParameter('kernel.root_dir', __DIR__ . '/temp');
$container->setParameter('kernel.cache_dir', __DIR__ . '/temp');
$container->setParameter('kernel.bundles', array());
return $container;
}
示例12: getContainer
private function getContainer()
{
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request');
$container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\AssetsHelper'));
$container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface')));
$container->register('twig', 'Twig_Environment');
$container->register('templating.engine.twig', $this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))->addArgument($this->getMock('Twig_Environment'))->addArgument($this->getMock('Symfony\\Component\\Templating\\TemplateNameParserInterface'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Config\\FileLocatorInterface')))->addArgument($this->getMock('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables', array(), array($this->getMock('Symfony\\Component\\DependencyInjection\\Container'))));
$container->setAlias('templating', 'templating.engine.twig');
$container->setParameter('kernel.bundles', array());
$container->setParameter('kernel.cache_dir', __DIR__);
$container->setParameter('kernel.root_dir', __DIR__);
$container->set('kernel', $this->kernel);
return $container;
}
示例13: ContainerBuilder
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Scope;
$container = new ContainerBuilder();
$container->addScope(new Scope('request'));
$container->register('foo', 'FooClass')->setScope('request');
$container->compile();
return $container;
示例14: addScope
public function addScope(ScopeInterface $scope)
{
return $this->delegate->addScope($scope);
}
示例15: cloneContainer
private function cloneContainer()
{
$parameterBag = new ParameterBag($this->container->getParameterBag()->all());
$container = new ContainerBuilder($parameterBag);
$container->setDefinitions($this->container->getDefinitions());
$container->setAliases($this->container->getAliases());
$container->setResources($this->container->getResources());
foreach ($this->container->getScopes() as $scope => $parentScope) {
$container->addScope(new Scope($scope, $parentScope));
}
foreach ($this->container->getExtensions() as $extension) {
$container->registerExtension($extension);
}
return $container;
}