PHP Class 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
See also: http://www.unicode.org/reports/tr35/#Number_Elements
See also: http://www.unicode.org/reports/tr35/#Number_Format_Patterns
Mostra file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$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.###', ... ), ... );

Public Methods

Method Description
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.

Protected Methods

Method Description
parseFormat ( string $format ) : array Parses a number format (with syntax defined in CLDR).

Method Details

getLocalizedSymbolsForLocale() public method

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
return array Symbols array

initializeObject() public method

Constructs the reader, loading parsed data from cache if available.
public initializeObject ( ) : void
return void

injectCache() public method

Injects the Flow_I18n_CDLR_Reader_NumbersReader cache
public injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void
$cache Neos\Cache\Frontend\VariableFrontend
return void

injectCldrRepository() public method

public injectCldrRepository ( CldrRepository $repository ) : void
$repository Neos\Flow\I18n\Cldr\CldrRepository
return void

parseCustomFormat() public method

Returns parsed date or time format string provided as parameter.
public parseCustomFormat ( string $format ) : array
$format string Format string to parse
return array An array representing parsed format

parseFormat() protected method

Not all features from CLDR specification are implemented. Please see the documentation for this class for details what is missing.
See also: NumbersReader::$parsedFormats
protected parseFormat ( string $format ) : array
$format string
return array Parsed format

parseFormatFromCldr() public method

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)
return array An array representing parsed format

shutdownObject() public method

Shutdowns the object, saving parsed format strings to the cache.
public shutdownObject ( ) : void
return void

validateFormatLength() public static method

Validates provided format length and throws exception if value is not allowed.
public static validateFormatLength ( string $formatLength ) : void
$formatLength string
return void

validateFormatType() public static method

Validates provided format type and throws exception if value is not allowed.
public static validateFormatType ( string $formatType ) : void
$formatType string
return void

Property Details

$cache protected_oe property

protected VariableFrontend,Neos\Cache\Frontend $cache
return Neos\Cache\Frontend\VariableFrontend

$cldrRepository protected_oe property

protected CldrRepository,Neos\Flow\I18n\Cldr $cldrRepository
return Neos\Flow\I18n\Cldr\CldrRepository

$localizedSymbols protected_oe property

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
return array

$parsedFormats protected_oe property

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
return array

$parsedFormatsIndices protected_oe property

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
return array