本文整理汇总了PHP中Joomla\DI\Container类的典型用法代码示例。如果您正苦于以下问题:PHP Container类的具体用法?PHP Container怎么用?PHP Container使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Container类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
});
}
示例2: 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)
{
$model = $this->model;
// QueryHelper
$container->share('model.' . $this->name . '.helper.query', function ($container) use($model) {
if ($model instanceof ListModel) {
return $model->getQueryHelper();
} else {
return new QueryHelper();
}
});
// Filter
$container->share('model.' . $this->name . '.filter', function ($container) use($model) {
if ($model instanceof ListModel) {
return $model->getFilterHelper();
} else {
return new FilterHelper();
}
})->alias('model.' . $this->name . '.helper.filter', 'model.' . $this->name . '.filter');
// Search
$container->share('model.' . $this->name . '.search', function ($container) use($model) {
if ($model instanceof ListModel) {
return $model->getSearchHelper();
} else {
return new SearchHelper();
}
})->alias('model.' . $this->name . '.helper.search', 'model.' . $this->name . '.search');
}
示例3: 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);
}
示例4: 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)
{
// Global Config
$container->share('joomla.config', array('JFactory', 'getConfig'));
// Windwalker Config
$container->share('windwalker.config', array($this, 'loadConfig'));
// Database
$this->share($container, 'db', 'JDatabaseDriver', array('JFactory', 'getDbo'));
// Language
$this->share($container, 'language', 'JLanguage', array('JFactory', 'getLanguage'));
// Dispatcher
$this->share($container, 'event.dispatcher', 'JEventDispatcher', array('JEventDispatcher', 'getInstance'));
// Date
$this->set($container, 'date', 'JDate', function () {
return DateHelper::getDate();
});
// Global
$container->set('SplPriorityQueue', function () {
return new \SplPriorityQueue();
});
// Asset
$container->share('helper.asset', function () {
return new \Windwalker\Helper\AssetHelper();
});
// Detect deferent environment
if (defined('WINDWALKER_CONSOLE')) {
$container->registerServiceProvider(new CliProvider());
} else {
$container->registerServiceProvider(new WebProvider());
}
}
示例5: register
/**
* Registers the service provider within a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.2
*/
public function register(Container $container)
{
$that = $this;
$container->share('logger', function (Container $c) use($that) {
return $that->getLogger($c);
}, true);
}
示例6: register
/**
* Registers the service provider within a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.2
*/
public function register(Container $container)
{
$that = $this;
$container->share('config', function ($c) use($that) {
return $that->getConfig($c);
}, true);
}
示例7: __construct
/**
* Instantiate the controller.
*
* @param \Joomla\DI\Container $container DI Container.
* @param IOInterface $io The Controller object.
*/
public function __construct(JoomlaContainer $container = null, IOInterface $io = null)
{
$this->container = $container ?: $this->getContainer();
// Set provider
$container->registerServiceProvider(new ServiceProvider());
parent::__construct($io);
}
示例8: register
/**
* {@inheritdoc}
*/
public function register(Container $container)
{
$config = $this->config;
$container->share('config', function () use($config) {
return $config;
});
}
示例9: register
/**
* Registers the service provider within a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 1.1
*/
public function register(Container $container)
{
$that = $this;
$container->share('github', function (Container $c) use($that) {
return $that->getGithub($c);
}, true);
}
示例10: 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');
}
}
示例11: 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);
}
示例12: 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);
}
示例13: testLoadFile
/**
* @testdox Loading a file
*/
public function testLoadFile()
{
$container = new Container();
$loader = new YamlLoader($container);
$loader->loadFromFile(dirname(__DIR__) . '/data/services.yml');
$this->assertEquals('called', $container->get('foo'));
}
示例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->share('cck', function ($container) {
return new CCKEngine($container->get('app'), $container->get('event.dispatcher'), $container);
});
\JForm::addFieldPath(__DIR__ . '/Fields');
\JForm::addFormPath(__DIR__ . '/Resource/Form');
}
示例15: 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');
}