PHP Класс Neos\Flow\I18n\Cldr\Reader\NumbersReader

The most important functionality of this class is formatting numbers. This is an implementation of Number Format Patterns as defined in Unicode Technical Standard #35. However, it's not complete implementation as for now. Following features are missing (in brackets - chapter from specification): - support for escaping of special characters in format string [part of G.2] - formatting numbers to scientific notation [G.4] - support for significant digits [G.5] - support for padding [G.6] - formatting numbers in other number systems than "latn" - currency symbol substitution is simplified
См. также: http://www.unicode.org/reports/tr35/#Number_Elements
См. также: http://www.unicode.org/reports/tr35/#Number_Format_Patterns
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$cache Neos\Cache\Frontend\VariableFrontend
$cldrRepository Neos\Flow\I18n\Cldr\CldrRepository
$localizedSymbols array Locale identifiers are keys for this array. Values are arrays of symbols, as defined in /ldml/numbers/symbols path in CLDR files.
$parsedFormats array Example of data stored in this array (default values): '#,##0.###' => array( 'positivePrefix' => '', 'positiveSuffix' => '', 'negativePrefix' => '-', 'negativeSuffix' => '', 'multiplier' => 1, 'minDecimalDigits' => 0, 'maxDecimalDigits' => 0, 'minIntegerDigits' => 1, 'primaryGroupingSize' => 0, 'secondaryGroupingSize' => 0, 'rounding' => 0.0, ); Legend: - positivePrefix / positiveSuffix: a character to place before / after the number, if it's positive. - negativePrefix / Suffix: same as above, but for negative numbers. - multiplier: Used for percents or permiles (100 and 1000 accordingly). - minDecimalDigits: same as above, but for decimal part of the number. No less than 0 (which means no decimal part). - maxDecimalDigits: same as above, but for decimal part of the number. No less than 0 (which means no decimal part). - minIntegerDigits: at least so many digits will be printed for integer part of the number (padded with zeros if needed). No less than 1. - primaryGroupingSize: Where to put the first grouping separator (e.g. thousands). Zero means no separator (also no secondary separator!). - secondaryGroupingSize: Where to put the second grouping separators (used after the primary separator - eg for primaryGroupingSize set to 3 and secondaryGroupingSize set to 2, number 123456789 will be 12,34,56,789). For most languages, this is the same as primaryGroupingSize. - rounding: If set, number will be rounded to the multiple of this value. Can be float or integer. Zero means no rounding. Note: there can be characters in prefix / suffix elements which will be localized during formatting (eg minus sign, percent etc), or other chars which will be used as-is.
$parsedFormatsIndices array As for one locale there can be defined many formats (at most 3 format types supported by this class - decimal, percent, currency - multiplied by at most 5 format lengths - full, long, medium, short, and implicit length referred in this class as 'default'), references are organized in arrays. Example of data stored in this array: 'pl' => array( 'decimal' => array( 'default' => '#,##0.###', ... ), ... );

Открытые методы

Метод Описание
getLocalizedSymbolsForLocale ( Locale $locale ) : array Returns symbols array for provided locale.
initializeObject ( ) : void Constructs the reader, loading parsed data from cache if available.
injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void Injects the Flow_I18n_CDLR_Reader_NumbersReader cache
injectCldrRepository ( CldrRepository $repository ) : void
parseCustomFormat ( string $format ) : array Returns parsed date or time format string provided as parameter.
parseFormatFromCldr ( Locale $locale, string $formatType, string $formatLength = self::FORMAT_LENGTH_DEFAULT ) : array Returns parsed number format basing on locale and desired format length if provided.
shutdownObject ( ) : void Shutdowns the object, saving parsed format strings to the cache.
validateFormatLength ( string $formatLength ) : void Validates provided format length and throws exception if value is not allowed.
validateFormatType ( string $formatType ) : void Validates provided format type and throws exception if value is not allowed.

Защищенные методы

Метод Описание
parseFormat ( string $format ) : array Parses a number format (with syntax defined in CLDR).

Описание методов

getLocalizedSymbolsForLocale() публичный Метод

Symbols are elements defined in tag symbols from CLDR. They define localized versions of various number-related elements, like decimal separator, group separator or minus sign. Symbols arrays for every requested locale are cached.
public getLocalizedSymbolsForLocale ( Locale $locale ) : array
$locale Neos\Flow\I18n\Locale
Результат array Symbols array

initializeObject() публичный Метод

Constructs the reader, loading parsed data from cache if available.
public initializeObject ( ) : void
Результат void

injectCache() публичный Метод

Injects the Flow_I18n_CDLR_Reader_NumbersReader cache
public injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void
$cache Neos\Cache\Frontend\VariableFrontend
Результат void

injectCldrRepository() публичный Метод

public injectCldrRepository ( CldrRepository $repository ) : void
$repository Neos\Flow\I18n\Cldr\CldrRepository
Результат void

parseCustomFormat() публичный Метод

Returns parsed date or time format string provided as parameter.
public parseCustomFormat ( string $format ) : array
$format string Format string to parse
Результат array An array representing parsed format

parseFormat() защищенный Метод

Not all features from CLDR specification are implemented. Please see the documentation for this class for details what is missing.
См. также: NumbersReader::$parsedFormats
protected parseFormat ( string $format ) : array
$format string
Результат array Parsed format

parseFormatFromCldr() публичный Метод

When third parameter ($formatLength) equals 'default', default format for a locale will be used.
public parseFormatFromCldr ( Locale $locale, string $formatType, string $formatLength = self::FORMAT_LENGTH_DEFAULT ) : array
$locale Neos\Flow\I18n\Locale
$formatType string A type of format (one of constant values)
$formatLength string A length of format (one of constant values)
Результат array An array representing parsed format

shutdownObject() публичный Метод

Shutdowns the object, saving parsed format strings to the cache.
public shutdownObject ( ) : void
Результат void

validateFormatLength() публичный статический Метод

Validates provided format length and throws exception if value is not allowed.
public static validateFormatLength ( string $formatLength ) : void
$formatLength string
Результат void

validateFormatType() публичный статический Метод

Validates provided format type and throws exception if value is not allowed.
public static validateFormatType ( string $formatType ) : void
$formatType string
Результат void

Описание свойств

$cache защищенное свойство

protected VariableFrontend,Neos\Cache\Frontend $cache
Результат Neos\Cache\Frontend\VariableFrontend

$cldrRepository защищенное свойство

protected CldrRepository,Neos\Flow\I18n\Cldr $cldrRepository
Результат Neos\Flow\I18n\Cldr\CldrRepository

$localizedSymbols защищенное свойство

Locale identifiers are keys for this array. Values are arrays of symbols, as defined in /ldml/numbers/symbols path in CLDR files.
protected array $localizedSymbols
Результат array

$parsedFormats защищенное свойство

Example of data stored in this array (default values): '#,##0.###' => array( 'positivePrefix' => '', 'positiveSuffix' => '', 'negativePrefix' => '-', 'negativeSuffix' => '', 'multiplier' => 1, 'minDecimalDigits' => 0, 'maxDecimalDigits' => 0, 'minIntegerDigits' => 1, 'primaryGroupingSize' => 0, 'secondaryGroupingSize' => 0, 'rounding' => 0.0, ); Legend: - positivePrefix / positiveSuffix: a character to place before / after the number, if it's positive. - negativePrefix / Suffix: same as above, but for negative numbers. - multiplier: Used for percents or permiles (100 and 1000 accordingly). - minDecimalDigits: same as above, but for decimal part of the number. No less than 0 (which means no decimal part). - maxDecimalDigits: same as above, but for decimal part of the number. No less than 0 (which means no decimal part). - minIntegerDigits: at least so many digits will be printed for integer part of the number (padded with zeros if needed). No less than 1. - primaryGroupingSize: Where to put the first grouping separator (e.g. thousands). Zero means no separator (also no secondary separator!). - secondaryGroupingSize: Where to put the second grouping separators (used after the primary separator - eg for primaryGroupingSize set to 3 and secondaryGroupingSize set to 2, number 123456789 will be 12,34,56,789). For most languages, this is the same as primaryGroupingSize. - rounding: If set, number will be rounded to the multiple of this value. Can be float or integer. Zero means no rounding. Note: there can be characters in prefix / suffix elements which will be localized during formatting (eg minus sign, percent etc), or other chars which will be used as-is.
protected array $parsedFormats
Результат array

$parsedFormatsIndices защищенное свойство

As for one locale there can be defined many formats (at most 3 format types supported by this class - decimal, percent, currency - multiplied by at most 5 format lengths - full, long, medium, short, and implicit length referred in this class as 'default'), references are organized in arrays. Example of data stored in this array: 'pl' => array( 'decimal' => array( 'default' => '#,##0.###', ... ), ... );
protected array $parsedFormatsIndices
Результат array