本文整理汇总了PHP中Container::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::has方法的具体用法?PHP Container::has怎么用?PHP Container::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Container
的用法示例。
在下文中一共展示了Container::has方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test1
public function test1()
{
$container = new Container();
$container->set('scalar', 42);
$this->assertEquals(42, $container->get('scalar'));
$this->assertTrue($container->has('scalar'));
$this->assertFalse($container->has('scalaR'));
}
示例2: testHasAndRemove
/**
* @param mixed $definition
*
* @dataProvider providerDefinitions
*/
public function testHasAndRemove($definition)
{
$di = new Container();
$di->set('test', $definition);
$this->assertTrue($di->has('test'));
$di->remove('test');
$this->assertFalse($di->has('test'));
}
示例3: testHasGet
/**
* @todo Implement testHas().
*/
public function testHasGet()
{
$expect = new \StdClass();
$this->container->set('foo', $expect);
$this->assertTrue($this->container->has('foo'));
$this->assertFalse($this->container->has('bar'));
$actual = $this->container->get('foo');
$this->assertSame($expect, $actual);
}
示例4:
/**
* Returns true if key exists in langs array
*
* @param string $name
* @return boolean
*/
function lang_exists($name)
{
if (is_null($name)) {
return false;
} else {
return $this->langs->has($name);
}
}
示例5: __construct
/**
* Constructor
*
* Instantiate the service locator object.
*
* @param array $services
*/
public function __construct(array $services = null)
{
if (null !== $services) {
$this->setServices($services);
}
if (!Container::has('default')) {
Container::set('default', $this);
}
}
示例6: testCreate
/**
* @covers ::__construct
* @covers ::initContainer
* @covers ::register
* @covers ::has
* @covers ::get
* @covers Nora\Core\DI\Exception\InstanceNotFound::__construct
* @expectedException Nora\Core\DI\Exception\InstanceNotFound
*/
public function testCreate()
{
$c = new Container();
$c->register(['hOge' => function () {
return new \StdClass();
}]);
$this->assertTrue($c->has('Hoge'));
$this->assertInstanceOf('StdClass', $c->get('hogE'));
$c->get('Hoge')->cnt = 0;
$c->get('hoGe')->cnt++;
$c->on('di.container.pre_get', function ($e) {
if (strtolower($e->name) === 'phpunit') {
$e->instance = $this;
}
});
$this->assertEquals($this, $c->get('phpUnit'));
$c->get('InvalidName');
}
示例7: has
/**
* Returns true if the given service is defined.
*
* @param string $id The service identifier
*
* @return Boolean true if the service is defined, false otherwise
*/
public function has($id)
{
return isset($this->definitions[$id]) || isset($this->aliases[$id]) || parent::has($id);
}
示例8: testRemove
/**
* @param Container $container
* @depends testMakeContainer
*/
public function testRemove(Container $container)
{
$this->assertEquals('H', $container->remove('h'));
$this->assertFalse($container->has('h'));
}