当前位置: 首页>>代码示例>>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;未经允许,请勿转载。