class NumbersReader (View source)

A reader for data placed in "numbers" tag in CLDR.

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

Constants

PATTERN_MATCH_SUBFORMAT

An expression to catch one subformat. One format string can have one or two subformats (positive and negative, separated by semicolon).

PATTERN_MATCH_ROUNDING

An expression to catch float or decimal number embedded in the format string, which sets a rounding used during formatting. For example, when format string looks like '#,##0.05', it means that formatted number should be rounded to the nearest 0.05.

FORMAT_TYPE_DECIMAL

Constants for available format types.

FORMAT_TYPE_PERCENT

FORMAT_TYPE_CURRENCY

FORMAT_LENGTH_DEFAULT

Constants for available format lengths.

FORMAT_LENGTH_FULL

FORMAT_LENGTH_LONG

FORMAT_LENGTH_MEDIUM

FORMAT_LENGTH_SHORT

Properties

protected CldrRepository $cldrRepository
protected VariableFrontend $cache
protected array $parsedFormats

An array of parsed formats, indexed by format strings.

protected array $parsedFormatsIndices

An array which stores references to formats used by particular locales.

protected array $localizedSymbols

Associative array of symbols used in particular locales.

Methods

void
injectCldrRepository(CldrRepository $repository)

No description

void
injectCache(VariableFrontend $cache)

Injects the Flow_I18n_CDLR_Reader_NumbersReader cache

void
initializeObject()

Constructs the reader, loading parsed data from cache if available.

void
shutdownObject()

Shutdowns the object, saving parsed format strings to the cache.

array
parseFormatFromCldr(Locale $locale, string $formatType, string $formatLength = self::FORMAT_LENGTH_DEFAULT)

Returns parsed number format basing on locale and desired format length if provided.

string
getDefaultNumberingSystem(Locale $locale)

No description

array
parseCustomFormat(string $format)

Returns parsed date or time format string provided as parameter.

array
getLocalizedSymbolsForLocale(Locale $locale)

Returns symbols array for provided locale.

static void
validateFormatType(string $formatType)

Validates provided format type and throws exception if value is not allowed.

static void
validateFormatLength(string $formatLength)

Validates provided format length and throws exception if value is not allowed.

array
parseFormat(string $format)

Parses a number format (with syntax defined in CLDR).

Details

void injectCldrRepository(CldrRepository $repository)

No description

Parameters

CldrRepository $repository

Return Value

void

void injectCache(VariableFrontend $cache)

Injects the Flow_I18n_CDLR_Reader_NumbersReader cache

Parameters

VariableFrontend $cache

Return Value

void

void initializeObject()

Constructs the reader, loading parsed data from cache if available.

Return Value

void

void shutdownObject()

Shutdowns the object, saving parsed format strings to the cache.

Return Value

void

Exceptions

Exception

array parseFormatFromCldr(Locale $locale, string $formatType, string $formatLength = self::FORMAT_LENGTH_DEFAULT)

Returns parsed number format basing on locale and desired format length if provided.

When third parameter ($formatLength) equals 'default', default format for a locale will be used.

Parameters

Locale $locale
string $formatType

A type of format (one of constant values)

string $formatLength

A length of format (one of constant values)

Return Value

array

An array representing parsed format

Exceptions

InvalidFormatLengthException
InvalidFormatTypeException
UnableToFindFormatException
UnsupportedNumberFormatException

string getDefaultNumberingSystem(Locale $locale)

No description

Parameters

Locale $locale

Return Value

string

array parseCustomFormat(string $format)

Returns parsed date or time format string provided as parameter.

Parameters

string $format

Format string to parse

Return Value

array

An array representing parsed format

Exceptions

UnsupportedNumberFormatException

array getLocalizedSymbolsForLocale(Locale $locale)

Returns symbols array for provided locale.

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.

Parameters

Locale $locale

Return Value

array

Symbols array

static void validateFormatType(string $formatType)

Validates provided format type and throws exception if value is not allowed.

Parameters

string $formatType

Return Value

void

Exceptions

InvalidFormatTypeException

static void validateFormatLength(string $formatLength)

Validates provided format length and throws exception if value is not allowed.

Parameters

string $formatLength

Return Value

void

Exceptions

InvalidFormatLengthException

protected array parseFormat(string $format)

Parses a number format (with syntax defined in CLDR).

Not all features from CLDR specification are implemented. Please see the documentation for this class for details what is missing.

Parameters

string $format

Return Value

array

Parsed format

Exceptions

UnsupportedNumberFormatException

See also

NumbersReader::$parsedFormats