本文整理汇总了PHP中Joomla\DI\Container::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::has方法的具体用法?PHP Container::has怎么用?PHP Container::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\DI\Container
的用法示例。
在下文中一共展示了Container::has方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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");
}
示例2: 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");
}
示例3: createCommandBus
/**
* @param Container $container The container
*
* @return \Joomla\Service\CommandBus
*/
public function createCommandBus(Container $container)
{
// Construct the command handler middleware
$middleware = [];
if ($container->has('CommandBusMiddleware')) {
$middleware = (array) $container->get('CommandBusMiddleware');
}
if ($container->has('extension_factory')) {
$middleware[] = new ExtensionQueryMiddleware($container->get('extension_factory'));
}
$builder = new CommandBusBuilder($container->get('EventDispatcher'));
$middleware = array_merge($middleware, $builder->getMiddleware());
$builder->setMiddleware($middleware);
return $builder->getCommandBus();
}
示例4: testDecorateArbitraryInteropContainerAlias
/**
* @testdox Container can manage an alias for a resource from an arbitrary Interop compatible container
*/
public function testDecorateArbitraryInteropContainerAlias()
{
$container = new Container(new \ArbitraryInteropContainer());
$container->alias('foo', 'aic_foo');
$this->assertTrue($container->has('foo'), "Container does not know alias 'foo'");
$this->assertEquals('aic_foo_content', $container->get('foo'), "Container does not return the correct value for alias 'foo'");
}
示例5: register
/**
* Add the configuration from the environment to a container
*
* @param Container $container The container
* @param string $alias An optional alias, defaults to 'config'
*
* @return void
*/
public function register(Container $container, $alias = 'config')
{
$file = '.env';
if ($container->has('ConfigFileName')) {
$file = $container->get('ConfigFileName');
}
$dotenv = new Dotenv($container->get('ConfigDirectory'), $file);
$dotenv->overload();
$container->set($alias, new Registry($_ENV), true);
}
示例6: testLoadWithInvalidClass
/**
* @testdox Loading an invalid class
*/
public function testLoadWithInvalidClass()
{
$content = <<<EOF
[providers]
foo = "\\NotAvailableServiceProvider"
EOF;
$container = new Container();
$loader = new IniLoader($container);
$loader->load($content);
$this->assertFalse($container->has('foo'));
}
示例7: createRepositoryFactory
/**
* Creates a RepositoryFactory
*
* @param Container $container The container
*
* @return RepositoryFactory
*/
public function createRepositoryFactory(Container $container)
{
$config = parse_ini_file(JPATH_ROOT . '/config/database.ini', true);
$configuration = new Configuration();
// Add logger
$logger = new DebugStack();
$configuration->setSQLLogger($logger);
$connection = DriverManager::getConnection(['url' => $config['databaseUrl']], $configuration);
$transactor = new DoctrineTransactor($connection);
$repositoryFactory = new RepositoryFactory($config, $connection, $transactor);
if ($container->has('dispatcher')) {
$repositoryFactory->setDispatcher($container->get('dispatcher'));
}
return $repositoryFactory;
}