當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Container::enterScope方法代碼示例

本文整理匯總了PHP中Symfony\Component\DependencyInjection\Container::enterScope方法的典型用法代碼示例。如果您正苦於以下問題:PHP Container::enterScope方法的具體用法?PHP Container::enterScope怎麽用?PHP Container::enterScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\DependencyInjection\Container的用法示例。


在下文中一共展示了Container::enterScope方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getTemplating

 /**
  * Retrieve the templating service
  * 
  * @return \Symfony\Bundle\FrameworkBundle\Templating\DelegatingEngine
  */
 public function getTemplating()
 {
     if (defined('IN_MAUTIC_CONSOLE')) {
         //enter the request scope in order to be use the templating.helper.assets service
         $this->container->enterScope('request');
         $this->container->set('request', new Request(), 'request');
     }
     return $this->container->get('templating');
 }
開發者ID:Yame-,項目名稱:mautic,代碼行數:14,代碼來源:TemplatingHelper.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: 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

示例4: 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

示例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: 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

示例8: 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

示例9: 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

示例10: 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


注:本文中的Symfony\Component\DependencyInjection\Container::enterScope方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。