本文整理汇总了PHP中Joomla\DI\Container::alias方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::alias方法的具体用法?PHP Container::alias怎么用?PHP Container::alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\DI\Container
的用法示例。
在下文中一共展示了Container::alias方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return Container Returns itself to support chaining.
*/
public function register(Container $container)
{
// Application
$container->alias('app', 'JApplicationCms')->share('JApplicationCms', array('JFactory', 'getApplication'));
// Document
$container->alias('document', 'JDocumentHtml')->share('JDocumentHtml', array('JFactory', 'getDocument'));
// User
$container->alias('user', 'JUser')->share('JUser', \JFactory::getUser());
// Input
$container->alias('input', 'JInput')->share('JInput', \JFactory::getApplication()->input);
}
示例2: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.0
*/
public function register(Container $container)
{
$container->alias('Stats\\Application', 'Joomla\\Application\\AbstractApplication')->alias('Joomla\\Application\\AbstractWebApplication', 'Joomla\\Application\\AbstractApplication')->share('Joomla\\Application\\AbstractApplication', function (Container $container) {
$application = new Application($container->get('Joomla\\Input\\Input'), $container->get('config'));
// Inject extra services
$application->setRouter($container->get('Stats\\Router'));
return $application;
}, true);
$container->share('Joomla\\Input\\Input', function () {
return new Input($_REQUEST);
}, true);
$container->share('Stats\\Router', function (Container $container) {
$router = (new Router($container->get('Joomla\\Input\\Input')))->setContainer($container)->setControllerPrefix('Stats\\Controllers\\')->setDefaultController('DisplayController')->addMap('/submit', 'SubmitController')->addMap('/:source', 'DisplayController');
return $router;
}, true);
$container->share('Stats\\Controllers\\DisplayControllerGet', function (Container $container) {
$controller = new DisplayControllerGet($container->get('Stats\\Views\\Stats\\StatsJsonView'));
$controller->setApplication($container->get('Joomla\\Application\\AbstractApplication'));
$controller->setInput($container->get('Joomla\\Input\\Input'));
return $controller;
}, true);
$container->share('Stats\\Controllers\\SubmitControllerCreate', function (Container $container) {
$controller = new SubmitControllerCreate($container->get('Stats\\Models\\StatsModel'));
$controller->setApplication($container->get('Joomla\\Application\\AbstractApplication'));
$controller->setInput($container->get('Joomla\\Input\\Input'));
return $controller;
}, true);
$container->share('Stats\\Models\\StatsModel', function (Container $container) {
return new StatsModel($container->get('Joomla\\Database\\DatabaseDriver'));
}, true);
$container->share('Stats\\Views\\Stats\\StatsJsonView', function (Container $container) {
return new StatsJsonView($container->get('Stats\\Models\\StatsModel'));
}, true);
}
示例3: register
public function register(Container $container)
{
$container->alias("db", "Joomla\\Database\\DatabaseDriver")->share("Joomla\\Database\\DatabaseDriver", function () use($container) {
$config = $container->get("config");
return DatabaseDriver::getInstance((array) $config["database"]);
}, true);
}
示例4: register
/**
* @param Container $container The DI container
* @param string $alias An optional alias
*
* @return void
*/
public function register(Container $container, $alias = null)
{
$container->set('CommandBus', [$this, 'createCommandBus'], true, true);
if ($alias) {
$container->alias($alias, 'CommandBus');
}
}
示例5: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.0
*/
public function register(Container $container)
{
// Register the web processor
$container->share('monolog.processor.web', function () {
return new WebProcessor();
});
// Register the main application handler
$container->share('monolog.handler.application', function (Container $container) {
/** @var \Joomla\Registry\Registry $config */
$config = $container->get('config');
$level = strtoupper($config->get('log.application', $config->get('log.level', 'error')));
return new StreamHandler(APPROOT . '/logs/app.log', constant('\\Monolog\\Logger::' . $level));
});
// Register the database handler
$container->share('monolog.handler.database', function (Container $container) {
/** @var \Joomla\Registry\Registry $config */
$config = $container->get('config');
// If database debugging is enabled then force the logger's error level to DEBUG, otherwise use the level defined in the app config
$level = $config->get('database.debug', false) ? 'DEBUG' : strtoupper($config->get('log.database', $config->get('log.level', 'error')));
return new StreamHandler(APPROOT . '/logs/database.log', constant('\\Monolog\\Logger::' . $level));
});
// Register the main Logger
$container->alias('monolog', 'Monolog\\Logger')->alias('monolog.logger.application', 'Monolog\\Logger')->alias('Psr\\Log\\LoggerInterface', 'Monolog\\Logger')->share('Monolog\\Logger', function (Container $container) {
return new Logger('MauticDashboard', [$container->get('monolog.handler.application')], [$container->get('monolog.processor.web')]);
});
// Register the database Logger
$container->share('monolog.logger.database', function (Container $container) {
return new Logger('MauticDashboard', [$container->get('monolog.handler.database')], [$container->get('monolog.processor.web')]);
});
}
示例6: 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'");
}
示例7: 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);
}
}
示例8: 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');
}
}
示例9: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.0
*/
public function register(Container $container)
{
$container->alias('db', 'Joomla\\Database\\DatabaseDriver')->share('Joomla\\Database\\DatabaseDriver', function (Container $container) {
$config = $container->get('config');
return DatabaseDriver::getInstance((array) $config['database']);
}, true);
}
示例10: 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);
}
}
示例11: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return Container Returns itself to support chaining.
*/
public function register(Container $container)
{
$name = $this->name;
// Component
$container->alias('component', ucfirst($name) . 'Component')->share(ucfirst($name) . 'Component', $this->component);
// ControllerResolver
$resolverClass = '\\Windwalker\\Controller\\Resolver\\ControllerResolver';
$container->alias('controller.resolver', $resolverClass)->share($resolverClass, function ($container) use($resolverClass) {
return new $resolverClass($container->get('app'), $container);
});
// Asset Helper
$container->extend('helper.asset', function ($asset, $container) use($name) {
$asset->resetPaths();
$asset = clone $asset;
return $asset->setName('com_' . strtolower($name))->setContainer($container);
});
}
示例12: 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');
}
示例13: 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)
{
$operators = array('copy', 'convert');
foreach ($operators as $operator) {
$class = '\\CodeGenerator\\FileOperator\\' . ucfirst($operator) . 'Operator';
$container->alias('operator.' . $operator, $class)->buildSharedObject($class);
}
}
示例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
*/
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');
}
示例15: register
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return Container Returns the container to support chaining.
*
* @since 1.0
* @throws \RuntimeException
*/
public function register(Container $container)
{
$container->share('JTracker\\Github\\Github', function () use($container) {
// Call the Github factory's getInstance method and inject the application; it handles the rest of the configuration
return GithubFactory::getInstance($container->get('app'));
}, true);
// Alias the object
$container->alias('gitHub', 'JTracker\\Github\\Github');
}