本文整理汇总了PHP中Joomla\DI\Container::extend方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::extend方法的具体用法?PHP Container::extend怎么用?PHP Container::extend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\DI\Container
的用法示例。
在下文中一共展示了Container::extend方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testExtendProtected
/**
* @testdox A protected resource can not be extended
* @expectedException \Joomla\DI\Exception\ProtectedKeyException
*/
public function testExtendProtected()
{
$container = new Container();
$container->protect('foo', function () {
return new \stdClass();
});
$value = 42;
$container->extend('foo', function ($shared) use($value) {
$shared->value = $value;
return $shared;
});
}
示例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)
{
$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);
});
}
示例3: testExtendValidatesKeyIsPresent
/**
* Testing the extend method to ensure that a valid key is present to extend.
*
* @return void
*
* @since 1.0
*
* @expectedException \InvalidArgumentException
*/
public function testExtendValidatesKeyIsPresent()
{
$this->fixture->extend('foo', function () {
// Noop.
});
}