本文整理汇总了PHP中Symfony\Component\Locale\Locale::getCountries方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getCountries方法的具体用法?PHP Locale::getCountries怎么用?PHP Locale::getCountries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Locale\Locale
的用法示例。
在下文中一共展示了Locale::getCountries方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
*
* @api
*/
public function validate($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
if (!in_array($value, \Symfony\Component\Locale\Locale::getCountries())) {
$this->context->addViolation($constraint->message, array('{{ value }}' => $value));
}
}
示例2: isValid
public function isValid($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
return true;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString()'))) {
throw new UnexpectedTypeException($value, 'string');
}
$value = (string) $value;
if (!in_array($value, Locale::getCountries())) {
$this->setMessage($constraint->message, array('{{ value }}' => $value));
return false;
}
return true;
}
示例3: testGetCountries
public function testGetCountries()
{
$countries = Locale::getCountries();
$this->assertTrue(in_array('BR', $countries));
}
示例4: testGetCountriesForSwitzerland
public function testGetCountriesForSwitzerland()
{
$countries = Locale::getCountries();
$this->assertContains('CH', $countries);
}
示例5: getCountries
public function getCountries()
{
return json_encode(\Symfony\Component\Locale\Locale::getCountries());
}