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


PHP Container::set方法代碼示例

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


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

示例1: testTheCommandBusHasAnExecuteMethodThatTakesAQueryAsAParameter

 /**
  * @testdox The modified command bus has an execute method that takes a Query as a parameter
  */
 public function testTheCommandBusHasAnExecuteMethodThatTakesAQueryAsAParameter()
 {
     $this->expectOutputString(sprintf("LOG: Starting %1\$s\nLOG: Ending %1\$s\n", "Joomla\\Tests\\Unit\\Service\\Stubs\\SimpleQuery"));
     $container = new Container();
     $container->set('EventDispatcher', $this->getMockBuilder(DispatcherInterface::class)->getMock());
     $container->set('CommandBusMiddleware', [new LoggingMiddleware(new Logger())]);
     $container->registerServiceProvider(new CommandBusServiceProvider());
     $commandBus = $container->get('CommandBus');
     $this->assertEquals('XSome contentY', $commandBus->handle(new SimpleQuery('Some content')));
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:13,代碼來源:CommandBusServiceProviderTest.php

示例2: testConfigServiceProviderCreatesConfigFromEnv

 /**
  * @testdox The ConfigServiceProvider adds an config to a container with variables from the environment
  */
 public function testConfigServiceProviderCreatesConfigFromEnv()
 {
     $container = new Container();
     $container->set('ConfigDirectory', __DIR__ . '/data');
     $container->set('ConfigFileName', 'env.txt');
     $service = new ConfigServiceProvider();
     $service->register($container);
     /** @var Registry $config * */
     $config = $container->get('config');
     $this->assertEquals('bar', $config->get('foo'));
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:14,代碼來源:ConfigServiceProviderTest.php

示例3: testExists

 /**
  * @testdox The existence of a resource can be checked
  */
 public function testExists()
 {
     $container = new Container();
     $container->set('foo', 'bar');
     $this->assertTrue($container->has('foo'), "'foo' should be present");
     $this->assertFalse($container->has('baz'), "'baz' should not be present");
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:10,代碼來源:ContainerAccessTest.php

示例4: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $app = $this->app;
     $container->set('app', function () use($app) {
         return $app;
     }, true, true);
 }
開發者ID:houzhenggang,項目名稱:cobalt,代碼行數:16,代碼來源:ApplicationServiceProvider.php

示例5: register

 /**
  * Add the plugin factory to a container
  *
  * @param   Container $container The container
  * @param   string    $alias     An optional alias
  *
  * @return  void
  */
 public function register(Container $container, $alias = null)
 {
     $container->set($this->key, [$this, 'createExtensionFactory'], true, true);
     if (!empty($alias)) {
         $container->alias($alias, $this->key);
     }
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:15,代碼來源:ExtensionFactoryServiceProvider.php

示例6: register

 /**
  * @param   Container $container The DI container
  * @param   string    $alias     An optional alias
  *
  * @return  void
  */
 public function register(Container $container, $alias = null)
 {
     $container->set('Request', [$this, 'createRequest'], true, true);
     if ($alias) {
         $container->alias($alias, 'Request');
     }
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:13,代碼來源:RequestServiceProvider.php

示例7: register

 /**
  * Registers a RepositoryFactory with the container
  *
  * @param   Container $container The DI container
  * @param   string    $alias     An optional alias
  *
  * @return  void
  */
 public function register(Container $container, $alias = null)
 {
     $container->set('Repository', [$this, 'createRepositoryFactory'], true, true);
     if (!empty($alias)) {
         $container->alias($alias, 'Repository');
     }
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:15,代碼來源:StorageServiceProvider.php

示例8: testGetNewInstance

 /**
  * Tests the getNew method which will always return a
  * new instance, even if the $key was set to be shared.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function testGetNewInstance()
 {
     $this->fixture->set('foo', function () {
         return new \stdClass();
     });
     $this->assertNotSame($this->fixture->getNewInstance('foo'), $this->fixture->getNewInstance('foo'));
 }
開發者ID:ZerGabriel,項目名稱:joomla-framework,代碼行數:15,代碼來源:ContainerTest.php

示例9: register

 /**
  * Add the dispatcher to a container
  *
  * @param   Container $container The container
  * @param   string    $alias     An optional alias
  *
  * @return  void
  */
 public function register(Container $container, $alias = null)
 {
     $container->set($this->key, [$this, 'createDispatcher'], true, true);
     if (!empty($alias)) {
         $container->alias($alias, $this->key);
     }
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:15,代碼來源:EventDispatcherServiceProvider.php

示例10: register

 /**
  * Registers the service provider within a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   2.0
  */
 public function register(Container $container)
 {
     $that = $this;
     $container->set('mustache', function ($c) use($that) {
         return $that->getMustache($c);
     });
 }
開發者ID:simonfork,項目名稱:tagaliser,代碼行數:16,代碼來源:MustacheServiceProvider.php

示例11: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->set('Joomla\\Database\\DatabaseDriver', function () {
         return (new DatabaseDriver())->create($this->test, 'mysqli');
     }, true, true);
     // Alias the database
     $container->alias('db', 'Joomla\\Database\\DatabaseDriver');
 }
開發者ID:ratto,項目名稱:framework.joomla.org,代碼行數:17,代碼來源:DatabaseProvider.php

示例12: testEventDispatcherServiceProviderCreatesDispatcherWithAlias

 /**
  * @testdox The EventDispatcherServiceProvider adds an EventDispatcher to a container with an alias
  */
 public function testEventDispatcherServiceProviderCreatesDispatcherWithAlias()
 {
     $container = new Container();
     $container->set('extension_factory', $this->getMockBuilder(ExtensionFactoryInterface::class)->getMock());
     $service = new EventDispatcherServiceProvider();
     $service->register($container, 'unit');
     $this->assertInstanceOf(DispatcherInterface::class, $container->get('unit'));
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:11,代碼來源:EventDispatcherServiceProviderTest.php

示例13: testExtensionFactoryServiceProviderCreatesExtensionFactoryWithAlias

 /**
  * @testdox The ExtensionFactoryServiceProvider adds an ExtensionFactory to a container with an alias
  */
 public function testExtensionFactoryServiceProviderCreatesExtensionFactoryWithAlias()
 {
     $container = new Container();
     $container->set('ConfigDirectory', __DIR__);
     $service = new ExtensionFactoryServiceProvider();
     $service->register($container, 'unit');
     $this->assertInstanceOf(ExtensionFactoryInterface::class, $container->get('unit'));
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:11,代碼來源:ExtensionFactoryServiceProviderTest.php

示例14: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  * @throws  \RuntimeException
  */
 public function register(Container $container)
 {
     $container->set('App\\Debug\\TrackerDebugger', function () use($container) {
         return new TrackerDebugger($container);
     }, true, true);
     // Alias the object
     $container->alias('debugger', 'App\\Debug\\TrackerDebugger');
 }
開發者ID:dextercowley,項目名稱:jissues,代碼行數:18,代碼來源:DebuggerProvider.php

示例15: testExistsResolvesAlias

 /**
  * @testdox has() also resolves the alias if set.
  */
 public function testExistsResolvesAlias()
 {
     $container = new Container();
     $container->set('foo', function () {
         return new \stdClass();
     }, true, true)->alias('bar', 'foo');
     $this->assertTrue($container->has('foo'), "Original 'foo' was not resolved");
     $this->assertTrue($container->has('bar'), "Alias 'bar' was not resolved");
 }
開發者ID:nibra,項目名稱:joomla-pythagoras,代碼行數:12,代碼來源:AliasingTest.php


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