本文整理汇总了PHP中Collator类的典型用法代码示例。如果您正苦于以下问题:PHP Collator类的具体用法?PHP Collator怎么用?PHP Collator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __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']);
// We don't want a number of countries which have ceased to exist
unset($source['SU']);
// Soviet Union
unset($source['BQ']);
// British Antarctic Territory
unset($source['CT']);
// Canton and Enderbury Islands
unset($source['NQ']);
// Dronning Maud Land
unset($source['FX']);
// France, Metropolitan
unset($source['FQ']);
// French Southern and Antarctic Territories
unset($source['NT']);
// Iraq-Saudi-Arabia Neutral Zone
unset($source['PZ']);
// Panama Canal Zone
unset($source['CS']);
// Serbia and Montenegro
}
parent::__construct($name, $title === null ? $name : $title, $source, $value, $form);
}
开发者ID:stadtwald,项目名称:silverstripe-framework,代码行数:36,代码来源:CountryDropdownField.php
示例17: finishView
public function finishView(FormView $view, FormInterface $form, array $options)
{
if ($view->children['country']->vars['choice_translation_domain'] === false) {
return;
}
$collator = new \Collator($this->translator->getLocale());
$translator = $this->translator;
$sortFunction = function ($a, $b) use($collator, $translator) {
return $collator->compare($translator->trans($a->label), $translator->trans($b->label));
};
usort($view->children['country']->vars['choices'], $sortFunction);
if (array_key_exists('state', $view->children) && $view->children['state']->vars['choice_translation_domain']) {
usort($view->children['state']->vars['choices'], $sortFunction);
}
if (array_key_exists('city', $view->children) && $view->children['city']->vars['choice_translation_domain']) {
usort($view->children['city']->vars['choices'], $sortFunction);
}
}
开发者ID:hackultura,项目名称:login-cidadao,代码行数:18,代码来源:CitySelectorComboType.php
示例18: generateFirstChars
function generateFirstChars()
{
$file = fopen("{$this->dataDir}/allkeys.txt", 'r');
if (!$file) {
$this->error("Unable to open allkeys.txt");
exit(1);
}
global $IP;
$outFile = fopen("{$IP}/serialized/first-letters-root.ser", 'w');
if (!$outFile) {
$this->error("Unable to open output file first-letters-root.ser");
exit(1);
}
$goodTertiaryChars = array();
// For each character with an entry in allkeys.txt, overwrite the implicit
// entry in $this->weights that came from the UCD.
// Also gather a list of tertiary weights, for use in selecting the group header
while (false !== ($line = fgets($file))) {
// We're only interested in single-character weights, pick them out with a regex
$line = trim($line);
if (!preg_match('/^([0-9A-F]+)\\s*;\\s*([^#]*)/', $line, $m)) {
continue;
}
$cp = hexdec($m[1]);
$allWeights = trim($m[2]);
$primary = '';
$tertiary = '';
if (!isset($this->weights[$cp])) {
// Non-printable, ignore
continue;
}
foreach (StringUtils::explode('[', $allWeights) as $weightStr) {
preg_match_all('/[*.]([0-9A-F]+)/', $weightStr, $m);
if (!empty($m[1])) {
if ($m[1][0] !== '0000') {
$primary .= '.' . $m[1][0];
}
if ($m[1][2] !== '0000') {
$tertiary .= '.' . $m[1][2];
}
}
}
$this->weights[$cp] = $primary;
if ($tertiary === '.0008' || $tertiary === '.000E') {
$goodTertiaryChars[$cp] = true;
}
}
fclose($file);
// Identify groups of characters with the same primary weight
$this->groups = array();
asort($this->weights, SORT_STRING);
$prevWeight = reset($this->weights);
$group = array();
foreach ($this->weights as $cp => $weight) {
if ($weight !== $prevWeight) {
$this->groups[$prevWeight] = $group;
$prevWeight = $weight;
if (isset($this->groups[$weight])) {
$group = $this->groups[$weight];
} else {
$group = array();
}
}
$group[] = $cp;
}
if ($group) {
$this->groups[$prevWeight] = $group;
}
// If one character has a given primary weight sequence, and a second
// character has a longer primary weight sequence with an initial
// portion equal to the first character, then remove the second
// character. This avoids having characters like U+A732 (double A)
// polluting the basic latin sort area.
foreach ($this->groups as $weight => $group) {
if (preg_match('/(\\.[0-9A-F]*)\\./', $weight, $m)) {
if (isset($this->groups[$m[1]])) {
unset($this->groups[$weight]);
}
}
}
ksort($this->groups, SORT_STRING);
// Identify the header character in each group
$headerChars = array();
$prevChar = "";
$tertiaryCollator = new Collator('root');
$primaryCollator = new Collator('root');
$primaryCollator->setStrength(Collator::PRIMARY);
$numOutOfOrder = 0;
foreach ($this->groups as $weight => $group) {
$uncomposedChars = array();
$goodChars = array();
foreach ($group as $cp) {
if (isset($goodTertiaryChars[$cp])) {
$goodChars[] = $cp;
}
if (!isset($this->mappedChars[$cp])) {
$uncomposedChars[] = $cp;
}
}
$x = array_intersect($goodChars, $uncomposedChars);
//.........这里部分代码省略.........
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:101,代码来源:generateCollationData.php
示例19: header
<?php header ('Content-Type: text/html; charset=UTF-8'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Collation in PHP</title>
</head>
<body style="font-size: 18pt;">
<?php # Script 14.3 - collation.php
// Create an array of words:
$words = array('chère', 'côté', 'chaise', 'château', 'chaînette', 'châle', 'Chère', 'côte', 'chemise');
// Sort using the default PHP function:
echo '<h3>Using sort()</h3>';
sort($words);
echo implode('<br />', $words);
// Sort using the Collator:
echo '<h3>Using Collator</h3>';
$c = new Collator('fr_FR');
$c->sort($words);
echo implode('<br />', $words);
?>
</body>
</html>
开发者ID:JangPooH,项目名称:Study,代码行数:28,代码来源:collation.php
示例20: __construct
function __construct($locale)
{
if (!extension_loaded('intl')) {
throw new MWException('An ICU collation was requested, ' . 'but the intl extension is not available.');
}
$this->locale = $locale;
$this->mainCollator = Collator::create($locale);
if (!$this->mainCollator) {
throw new MWException("Invalid ICU locale specified for collation: {$locale}");
}
$this->primaryCollator = Collator::create($locale);
$this->primaryCollator->setStrength(Collator::PRIMARY);
}
开发者ID:mangowi,项目名称:mediawiki,代码行数:13,代码来源:Collation.php
注:本文中的Collator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论