当前位置: 首页>>代码示例>>PHP>>正文


PHP Collator类代码示例

本文整理汇总了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);
 }
开发者ID:laubosslink,项目名称:lab,代码行数:10,代码来源:StubCollatorTest.php

示例2: sortByValue

 protected function sortByValue($collection)
 {
     $collator = new \Collator('fr_FR');
     $items = iterator_to_array($collection);
     $collator->asort($items);
     return new Map($items);
 }
开发者ID:polem,项目名称:departements,代码行数:7,代码来源:AbstractDatasource.php

示例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();
     }
 }
开发者ID:wirecard,项目名称:magento-wcs,代码行数:25,代码来源:Abstract.php

示例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);
     }
 }
开发者ID:anime-db,项目名称:catalog-bundle,代码行数:14,代码来源:ViewSorter.php

示例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;
 }
开发者ID:sanborino,项目名称:clinica,代码行数:13,代码来源:IcuCurrencyBundle.php

示例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;
 }
开发者ID:sanborino,项目名称:clinica,代码行数:13,代码来源:IcuLanguageBundle.php

示例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);
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:15,代码来源:AbstractCurrencyDataProviderTest.php

示例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;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:13,代码来源:ScriptDataProvider.php

示例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;
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:13,代码来源:LocaleChoiceList.php

示例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);
     }
 }
开发者ID:raz0rsdge,项目名称:horde,代码行数:13,代码来源:ClientSort.php

示例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}");
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:15,代码来源:CollationTest.php

示例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];
 }
开发者ID:spf13,项目名称:symfony,代码行数:27,代码来源:Locale.php

示例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;
 }
开发者ID:sanborino,项目名称:clinica,代码行数:26,代码来源:IcuRegionBundle.php

示例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);
 }
开发者ID:normann,项目名称:sapphire,代码行数:17,代码来源:CountryDropdownField.php

示例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);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:20,代码来源:CountryDropdownField.php


注:本文中的Collator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。