本文整理汇总了PHP中Joomla\DI\Container::protect方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::protect方法的具体用法?PHP Container::protect怎么用?PHP Container::protect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\DI\Container
的用法示例。
在下文中一共展示了Container::protect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testProtectShared
/**
* Tests the protected method when passing the shared arg..
*
* @return void
*
* @since 1.0
*/
public function testProtectShared()
{
$this->fixture->protect('foo', function () {
return new \stdClass();
}, true);
$dataStore = $this->readAttribute($this->fixture, 'dataStore');
$this->assertTrue($dataStore['foo']['protected'], 'The protect convenience method sets items as protected.');
$this->assertTrue($dataStore['foo']['shared'], 'The protected method does set shared when passed true as third arg.');
}
示例2: 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;
});
}
示例3: 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)
{
require_once JPATH_CONFIGURATION . '/configuration.php';
$config = new Registry(new JConfig());
// Set the error_reporting
switch ($config->get('error_reporting')) {
case 'default':
case '-1':
break;
case 'none':
case '0':
error_reporting(0);
break;
case 'simple':
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('display_errors', 1);
break;
case 'maximum':
error_reporting(E_ALL);
ini_set('display_errors', 1);
break;
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
default:
error_reporting($config->get('error_reporting'));
ini_set('display_errors', 1);
break;
}
JFactory::$config = $config;
define('JDEBUG', $config->get('debug', false));
$container->protect('config', function () use($config) {
return $config;
}, true);
}
示例4: testProtectShared
/**
* @testdox The convenience method protect() sets resources as shared when passed true as third arg
*/
public function testProtectShared()
{
$container = new Container();
$container->protect('foo', function () {
return new \StdClass();
}, true);
$this->assertTrue($container->isShared('foo'));
$this->assertTrue($container->isProtected('foo'));
}