当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::addScope方法代码示例

本文整理汇总了PHP中Symfony\Component\DependencyInjection\Container::addScope方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::addScope方法的具体用法?PHP Container::addScope怎么用?PHP Container::addScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DependencyInjection\Container的用法示例。


在下文中一共展示了Container::addScope方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUp

    protected function setUp()
    {
        parent::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->register('templating.engine.twig', $this->getMockClass('Symfony\\Bundle\\TwigBundle\\TwigEngine'))
            ->addArgument(new Definition($this->getMockClass('Twig_Environment')))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\TemplateNameParserInterface')))
            ->addArgument(new Definition($this->getMockClass('Symfony\Component\Config\FileLocatorInterface')))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\GlobalVariables'), array(new Definition($this->getMockClass('Symfony\\Component\\DependencyInjection\\Container')))));
        $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->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'))
            ->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface')));
        $this->container->setParameter('data_collector.templates', array());
        $this->container->set('kernel', $this->kernel);
    }
开发者ID:n3b,项目名称:symfony,代码行数:27,代码来源:WebProfilerExtensionTest.php

示例2: setUp

 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->container = new Container();
     $this->container->addScope(new Scope('request'));
     $this->container->enterScope('request');
     $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface');
     $translator->expects($this->any())->method('getLocale')->will($this->returnValue('fr_FR'));
     $this->container->set('translator', $translator);
 }
开发者ID:boskee,项目名称:HearsayRequireJSBundle,代码行数:13,代码来源:ConfigurationBuilderTest.php

示例3: setUp

 protected function setUp()
 {
     parent::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('router', $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('kernel.debug', false);
     $this->container->setParameter('kernel.root_dir', __DIR__);
     $this->container->setParameter('profiler.class', array('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'));
     $this->container->register('profiler', $this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\Profiler'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\HttpKernel\\Profiler\\ProfilerStorageInterface')));
     $this->container->setParameter('data_collector.templates', array());
     $this->container->set('kernel', $this->kernel);
 }
开发者ID:RuntyCybin,项目名称:csymfony,代码行数:18,代码来源:WebProfilerExtensionTest.php

示例4: getContainer

 /**
  * @param Request $request
  *
  * @return Container
  */
 public function getContainer(Request $request = null)
 {
     $container = new Container();
     if ($request !== null) {
         $container->addScope(new Scope('request'));
         $container->enterScope('request');
         $container->set('request', $request);
     }
     return $container;
 }
开发者ID:asev,项目名称:SettingsBundle,代码行数:15,代码来源:HiddenExtensionTest.php

示例5: testTokenNotAddedToSubrequest

 /**
  * Tests that the token is not added to a subrequest.
  */
 public function testTokenNotAddedToSubrequest()
 {
     /** @var HttpKernelInterface $kernel */
     $kernel = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Kernel', ['test', false]);
     $request = new Request();
     $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
     $listener = new RefererIdListener($this->mockTokenManager());
     $container = new Container();
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_BACKEND));
     $container->enterScope(ContaoCoreBundle::SCOPE_BACKEND);
     $listener->setContainer($container);
     $listener->onKernelRequest($event);
     $this->assertFalse($request->attributes->has('_contao_referer_id'));
 }
开发者ID:jamesdevine,项目名称:core-bundle,代码行数:17,代码来源:RefererIdListenerTest.php

示例6: testInvalidScope

 /**
  * Tests that there is no repsonse if the scope is not "frontend".
  */
 public function testInvalidScope()
 {
     /** @var HttpKernelInterface $kernel */
     $kernel = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Kernel', ['test', false]);
     $container = new Container();
     $request = new Request();
     $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
     $listener = new OutputFromCacheListener($this->framework);
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_BACKEND));
     $container->enterScope(ContaoCoreBundle::SCOPE_BACKEND);
     $request->attributes->set('_route', 'dummy');
     $listener->setContainer($container);
     $listener->onKernelRequest($event);
     $this->assertFalse($event->hasResponse());
 }
开发者ID:Mozan,项目名称:core-bundle,代码行数:18,代码来源:OutputFromCacheListenerTest.php

示例7: testReEnteringAScope

 public function testReEnteringAScope()
 {
     $event = new Event();
     $service1 = $this->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service');
     $service1->expects($this->exactly(2))->method('onEvent')->with($event);
     $scope = new Scope('scope');
     $container = new Container();
     $container->addScope($scope);
     $container->enterScope('scope');
     $container->set('service.listener', $service1, 'scope');
     $dispatcher = new ContainerAwareEventDispatcher($container);
     $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
     $dispatcher->dispatch('onEvent', $event);
     $service2 = $this->getMock('Symfony\\Component\\EventDispatcher\\Tests\\Service');
     $service2->expects($this->once())->method('onEvent')->with($event);
     $container->enterScope('scope');
     $container->set('service.listener', $service2, 'scope');
     $dispatcher->dispatch('onEvent', $event);
     $container->leaveScope('scope');
     $dispatcher->dispatch('onEvent');
 }
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:21,代码来源:ContainerAwareEventDispatcherTest.php

示例8: testIsScopeActive

 /**
  * @group legacy
  */
 public function testIsScopeActive()
 {
     $c = new Container();
     $this->assertFalse($c->isScopeActive('foo'));
     $c->addScope(new Scope('foo'));
     $this->assertFalse($c->isScopeActive('foo'));
     $c->enterScope('foo');
     $this->assertTrue($c->isScopeActive('foo'));
     $c->leaveScope('foo');
     $this->assertFalse($c->isScopeActive('foo'));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:ContainerTest.php

示例9: testGetGlobalsInActiveRequestScope

 /**
  * @covers Hearsay\RequireJSBundle\Twig\Extension\RequireJSExtension::getGlobals
  */
 public function testGetGlobalsInActiveRequestScope()
 {
     $this->container->addScope(new Scope('request'));
     $this->container->enterScope('request');
     $this->assertEquals(array('require_js' => array('config' => array())), $this->extension->getGlobals());
 }
开发者ID:boskee,项目名称:HearsayRequireJSBundle,代码行数:9,代码来源:RequireJSExtensionTest.php

示例10: testSupportsClass

 /**
  * Tests the supportsClass() method.
  */
 public function testSupportsClass()
 {
     $container = new Container();
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_FRONTEND));
     $container->enterScope(ContaoCoreBundle::SCOPE_FRONTEND);
     $provider = new ContaoUserProvider($container, $this->framework);
     $this->assertTrue($provider->supportsClass('Contao\\FrontendUser'));
 }
开发者ID:jamesdevine,项目名称:core-bundle,代码行数:11,代码来源:ContaoUserProviderTest.php

示例11: testCookiePath

 /**
  * Tests the cookie path.
  */
 public function testCookiePath()
 {
     /** @var HttpKernelInterface $kernel */
     $kernel = $this->getMockForAbstractClass('Symfony\\Component\\HttpKernel\\Kernel', ['test', false]);
     $container = new Container();
     $request = new Request(['toggle_view' => 'desktop']);
     $event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
     $listener = new ToggleViewListener($this->framework);
     $reflection = new \ReflectionClass($request);
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_FRONTEND));
     $container->enterScope(ContaoCoreBundle::SCOPE_FRONTEND);
     $request->attributes->set('_route', 'dummy');
     // Set the base path to /foo/bar
     $basePath = $reflection->getProperty('basePath');
     $basePath->setAccessible(true);
     $basePath->setValue($request, '/foo/bar');
     $listener->setContainer($container);
     $listener->onKernelRequest($event);
     $this->assertTrue($event->hasResponse());
     $cookie = $this->getCookie($event->getResponse());
     $this->assertEquals('/foo/bar', $cookie->getPath());
 }
开发者ID:jamesdevine,项目名称:core-bundle,代码行数:25,代码来源:ToggleViewListenerTest.php

示例12: mockContainerWithContaoScopes

 /**
  * Mocks a container with scopes.
  *
  * @return Container|\PHPUnit_Framework_MockObject_MockObject The container object
  */
 protected function mockContainerWithContaoScopes()
 {
     $container = new Container();
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_BACKEND));
     $container->addScope(new Scope(ContaoCoreBundle::SCOPE_FRONTEND));
     $container->setParameter('kernel.root_dir', $this->getRootDir());
     $container->setParameter('kernel.cache_dir', $this->getCacheDir());
     $container->setParameter('kernel.debug', false);
     $container->setParameter('contao.image.bypass_cache', false);
     $container->setParameter('contao.image.target_path', 'assets/images');
     $container->set('contao.resource_finder', new ResourceFinder($this->getRootDir() . '/vendor/contao/test-bundle/Resources/contao'));
     $container->set('contao.resource_locator', new FileLocator($this->getRootDir() . '/vendor/contao/test-bundle/Resources/contao'));
     $request = new Request();
     $request->server->set('REMOTE_ADDR', '123.456.789.0');
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $container->set('request_stack', $requestStack);
     $container->set('session', $this->mockSession());
     return $container;
 }
开发者ID:Mozan,项目名称:core-bundle,代码行数:25,代码来源:TestCase.php


注:本文中的Symfony\Component\DependencyInjection\Container::addScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。