當前位置: 首頁>>代碼示例>>PHP>>正文


PHP BuilderConfiguration::hasAlias方法代碼示例

本文整理匯總了PHP中Symfony\Components\DependencyInjection\BuilderConfiguration::hasAlias方法的典型用法代碼示例。如果您正苦於以下問題:PHP BuilderConfiguration::hasAlias方法的具體用法?PHP BuilderConfiguration::hasAlias怎麽用?PHP BuilderConfiguration::hasAlias使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Components\DependencyInjection\BuilderConfiguration的用法示例。


在下文中一共展示了BuilderConfiguration::hasAlias方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: BuilderConfiguration

$t->ok(!$configuration->hasParameter('bar'), '->hasParameter() returns false if a parameter is not defined');

// ->addParameters()
$t->diag('->addParameters()');
$configuration = new BuilderConfiguration(array(), array('foo' => 'bar'));
$configuration->addParameters(array('bar' => 'foo'));
$t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'foo'), '->addParameters() adds parameters to the existing ones');
$configuration->addParameters(array('Bar' => 'fooz'));
$t->is($configuration->getParameters(), array('foo' => 'bar', 'bar' => 'fooz'), '->addParameters() converts keys to lowercase');

// ->setAlias() ->getAlias() ->hasAlias() ->getAliases() ->addAliases()
$t->diag('->setAlias() ->getAlias() ->hasAlias()');
$configuration = new BuilderConfiguration();
$configuration->setAlias('bar', 'foo');
$t->is($configuration->getAlias('bar'), 'foo', '->setAlias() defines a new alias');
$t->ok($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined');
$t->ok(!$configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined');

try
{
  $configuration->getAlias('baba');
  $t->fail('->getAlias() throws an \InvalidArgumentException if the alias does not exist');
}
catch (\InvalidArgumentException $e)
{
  $t->pass('->getAlias() throws an \InvalidArgumentException if the alias does not exist');
}

$configuration->setAlias('barbar', 'foofoo');
$t->is($configuration->getAliases(), array('bar' => 'foo', 'barbar' => 'foofoo'), '->getAliases() returns an array of all defined aliases');
開發者ID:nicolasmartin,項目名稱:symfony,代碼行數:30,代碼來源:BuilderConfigurationTest.php

示例2: testAliases

 public function testAliases()
 {
     $configuration = new BuilderConfiguration();
     $configuration->setAlias('bar', 'foo');
     $this->assertEquals('foo', $configuration->getAlias('bar'), '->setAlias() defines a new alias');
     $this->assertTrue($configuration->hasAlias('bar'), '->hasAlias() returns true if the alias is defined');
     $this->assertFalse($configuration->hasAlias('baba'), '->hasAlias() returns false if the alias is not defined');
     try {
         $configuration->getAlias('baba');
         $this->fail('->getAlias() throws an \\InvalidArgumentException if the alias does not exist');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\InvalidArgumentException', $e, '->getAlias() throws an \\InvalidArgumentException if the alias does not exist');
         $this->assertEquals('The service alias "baba" does not exist.', $e->getMessage(), '->getAlias() throws an \\InvalidArgumentException if the alias does not exist');
     }
     $configuration->setAlias('barbar', 'foofoo');
     $this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo'), $configuration->getAliases(), '->getAliases() returns an array of all defined aliases');
     $configuration->addAliases(array('foo' => 'bar'));
     $this->assertEquals(array('bar' => 'foo', 'barbar' => 'foofoo', 'foo' => 'bar'), $configuration->getAliases(), '->addAliases() adds some aliases');
 }
開發者ID:jacques-sounvi,項目名稱:addressbook,代碼行數:19,代碼來源:BuilderConfigurationTest.php


注:本文中的Symfony\Components\DependencyInjection\BuilderConfiguration::hasAlias方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。