本文整理汇总了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')));
}
示例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'));
}
示例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");
}
示例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);
}
示例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);
}
}
示例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');
}
}
示例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');
}
}
示例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'));
}
示例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);
}
}
示例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);
});
}
示例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');
}
示例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'));
}
示例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'));
}
示例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');
}
示例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");
}