本文整理汇总了PHP中Collator类的典型用法代码示例。如果您正苦于以下问题:PHP Collator类的具体用法?PHP Collator怎么用?PHP Collator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAsortIntl
/**
* @dataProvider asortProvider
*/
public function testAsortIntl($array, $sortFlag, $expected)
{
$this->skipIfIntlExtensionIsNotLoaded();
$collator = new \Collator('en');
$collator->asort($array, $sortFlag);
$this->assertSame($expected, $array);
}
示例2: sortByValue
protected function sortByValue($collection)
{
$collator = new \Collator('fr_FR');
$items = iterator_to_array($collection);
$collator->asort($items);
return new Map($items);
}
示例3: getFinancialInstitutions
public function getFinancialInstitutions()
{
/** @var Wirecard_CheckoutSeamless_Helper_Data $helper */
$helper = Mage::helper('wirecard_checkoutseamless');
$cl = new WirecardCEE_QMore_BackendClient($helper->getBackendConfigArray());
$response = $cl->getFinancialInstitutions($this->getMethod()->getPaymentMethodType());
if (!$response->hasFailed()) {
$ret = $response->getFinancialInstitutions();
$c = null;
if (class_exists('Collator')) {
$c = new Collator('root');
}
uasort($ret, function ($a, $b) use($c) {
if ($c === null) {
return strcmp($a['id'], $b['id']);
} else {
return $c->compare($a['name'], $b['name']);
}
});
return $ret;
} else {
$helper->log(__METHOD__ . ':' . print_r($response->getErrors(), true), LOG_WARNING);
return array();
}
}
示例4: compare
/**
* @param string $a
* @param string $b
*
* @return int
*/
public function compare($a, $b)
{
if ($this->collator instanceof \Collator) {
return $this->collator->compare($a, $b);
} else {
return $a == $b ? 0 : ($a > $b ? 1 : -1);
}
}
示例5: getCurrencyNames
/**
* {@inheritdoc}
*/
public function getCurrencyNames($locale = null)
{
if (null === $locale) {
$locale = \Locale::getDefault();
}
$names = parent::getCurrencyNames($locale);
$collator = new \Collator($locale);
$collator->asort($names);
return $names;
}
示例6: getScriptNames
/**
* {@inheritdoc}
*/
public function getScriptNames($locale = null)
{
if (null === $locale) {
$locale = \Locale::getDefault();
}
$scripts = parent::getScriptNames($locale);
$collator = new \Collator($locale);
$collator->asort($scripts);
return $scripts;
}
示例7: testGetNames
/**
* @dataProvider provideLocales
*/
public function testGetNames($displayLocale)
{
$names = $this->dataProvider->getNames($displayLocale);
$keys = array_keys($names);
sort($keys);
$this->assertEquals(static::$currencies, $keys);
// Names should be sorted
$sortedNames = $names;
$collator = new \Collator($displayLocale);
$collator->asort($names);
$this->assertSame($sortedNames, $names);
}
示例8: getNames
public function getNames($displayLocale = null)
{
if (null === $displayLocale) {
$displayLocale = Locale::getDefault();
}
$names = $this->reader->readEntry($this->path, $displayLocale, array('Names'));
if ($names instanceof \Traversable) {
$names = iterator_to_array($names);
}
$collator = new \Collator($displayLocale);
$collator->asort($names);
return $names;
}
示例9: getRemainingViews
/**
* Returns the remaining locales sorted by language name
*
* @return array
*/
public function getRemainingViews()
{
$remainingViews = parent::getRemainingViews();
usort($remainingViews, function (ChoiceView $choiceView1, ChoiceView $choiceView2) {
return \Collator::create(null)->compare($choiceView1->label, $choiceView2->label);
});
return $remainingViews;
}
示例10: _sortString
/**
* Sort an array of strings based on current locale.
*
* @param array &$sorted Array of strings.
*/
protected function _sortString(&$sorted)
{
if (empty($this->_collator)) {
asort($sorted, SORT_LOCALE_STRING);
} else {
$this->_collator->asort($sorted, Collator::SORT_STRING);
}
}
示例11: testNotIsPrefix
/**
* Opposite of testIsPrefix
*
* @dataProvider notPrefixDataProvider
*/
function testNotIsPrefix($lang, $base, $extended)
{
$cp = Collator::create($lang);
$cp->setStrength(Collator::PRIMARY);
$baseBin = $cp->getSortKey($base);
// Remove sortkey terminator
$baseBin = rtrim($baseBin, "");
$extendedBin = $cp->getSortKey($extended);
$this->assertStringStartsNotWith($baseBin, $extendedBin, "{$base} is a prefix of {$extended}");
}
示例12: getDisplayLanguages
/**
* Returns the language names for a locale
*
* @param string $locale The locale to use for the language names
* @return array The language names with their codes as keys
* @throws RuntimeException When the resource bundles cannot be loaded
*/
public static function getDisplayLanguages($locale)
{
if (!isset(self::$languages[$locale])) {
$bundle = new \ResourceBundle($locale, __DIR__ . '/Resources/data/lang');
if (null === $bundle) {
throw new \RuntimeException('The language resource bundle could not be loaded');
}
$collator = new \Collator($locale);
$languages = array();
foreach ($bundle->get('Languages') as $code => $name) {
// "mul" is the code for multiple languages
if ('mul' !== $code) {
$languages[$code] = $name;
}
}
$collator->asort($languages);
self::$languages[$locale] = $languages;
}
return self::$languages[$locale];
}
示例13: getCountryNames
/**
* {@inheritdoc}
*/
public function getCountryNames($locale = null)
{
if (null === $locale) {
$locale = \Locale::getDefault();
}
$countries = parent::getCountryNames($locale);
// "ZZ" is the code for unknown country
unset($countries['ZZ']);
// Global countries (f.i. "America") have numeric codes
// Countries have alphabetic codes
foreach ($countries as $code => $name) {
// is_int() does not work, since some numbers start with '0' and
// thus are stored as strings.
// The (string) cast is necessary since ctype_digit() returns false
// for integers.
if (ctype_digit((string) $code)) {
unset($countries[$code]);
}
}
$collator = new \Collator($locale);
$collator->asort($countries);
return $countries;
}
示例14: __construct
public function __construct($name, $title = null, $source = null, $value = "", $form = null)
{
if (!is_array($source)) {
// Get a list of countries from Zend
$source = Zend_Locale::getTranslationList('territory', $this->locale(), 2);
// We want them ordered by display name, not country code
// PHP 5.3 has an extension that sorts UTF-8 strings correctly
if (class_exists('Collator') && ($collator = Collator::create($this->locale()))) {
$collator->asort($source);
} else {
asort($source);
}
// We don't want "unknown country" as an option
unset($source['ZZ']);
}
parent::__construct($name, $title === null ? $name : $title, $source, $value, $form);
}
示例15: setSource
public function setSource($source)
{
if ($source) {
return parent::setSource($source);
}
// map empty source to country list
// Get a list of countries from Zend
$source = Zend_Locale::getTranslationList('territory', $this->locale(), 2);
// We want them ordered by display name, not country code
// PHP 5.3 has an extension that sorts UTF-8 strings correctly
if (class_exists('Collator') && ($collator = Collator::create($this->locale()))) {
$collator->asort($source);
} else {
// Otherwise just put up with them being weirdly ordered for now
asort($source);
}
// We don't want "unknown country" as an option
unset($source['ZZ']);
return parent::setSource($source);
}