class CldrModel (View source)

A model representing data from one or few CLDR files.

When more than one file path is provided to the constructor, data from all files will be parsed and merged according to the inheritance rules defined in CLDR specification. Aliases are also resolved correctly.

Properties

protected string $cldrBasePath

An absolute path to the directory where CLDR resides. It is changed only in tests.

protected VariableFrontend $cache
protected string $cacheKey

Key used to store / retrieve cached data

protected CldrParser $cldrParser
protected string[] $sourcePaths

Absolute path or path to the files represented by this class' instance.

protected array $parsedData

Methods

__construct(array $sourcePaths)

Contructs the model

void
injectCache(VariableFrontend $cache)

Injects the Flow_I18n_Cldr_CldrModelCache cache

void
injectParser(CldrParser $parser)

No description

void
initializeObject()

When it's called, CLDR file is parsed or cache is loaded, if available.

mixed
getRawData(string $path)

Returns multi-dimensional array representing desired node and it's children, or a string value if the path points to a leaf.

mixed
getRawArray(string $path)

Returns multi-dimensional array representing desired node and it's children.

mixed
getElement(string $path)

Returns string value from a path given.

mixed
findNodesWithinPath(string $path, string $nodeName)

Returns all nodes with given name found within given path

static string
getNodeName(string $nodeString)

Returns node name extracted from node string

static mixed
getAttributeValue(string $nodeString, string $attributeName)

Parses the node string and returns a value of attribute for name provided.

array
parseFiles(array $sourcePaths)

Parses given CLDR files using CldrParser and merges parsed data.

array
mergeTwoParsedFiles(mixed $firstParsedData, mixed $secondParsedData)

Merges two sets of data from two separate CLDR files into one array.

mixed
resolveAliases(mixed $data, string $currentPath)

Resolves any 'alias' nodes in parsed CLDR data.

Details

__construct(array $sourcePaths)

Contructs the model

Accepts array of absolute paths to CLDR files. This array can have one element (if model represents one CLDR file) or many elements (if group of CLDR files is going to be represented by this model).

Parameters

array $sourcePaths

void injectCache(VariableFrontend $cache)

Injects the Flow_I18n_Cldr_CldrModelCache cache

Parameters

VariableFrontend $cache

Return Value

void

void injectParser(CldrParser $parser)

No description

Parameters

CldrParser $parser

Return Value

void

void initializeObject()

When it's called, CLDR file is parsed or cache is loaded, if available.

Return Value

void

mixed getRawData(string $path)

Returns multi-dimensional array representing desired node and it's children, or a string value if the path points to a leaf.

Syntax for paths is very simple. It's a group of array indices joined with a slash. It tries to emulate XPath query syntax to some extent. Examples:

plurals/pluralRules dates/calendars/calendar[@type="gregorian"]

Please see the documentation for CldrParser for details about parsed data structure.

Parameters

string $path

A path to the node to get

Return Value

mixed

Array or string of matching data, or false on failure

See also

CldrParser

mixed getRawArray(string $path)

Returns multi-dimensional array representing desired node and it's children.

This method will return false if the path points to a leaf (i.e. a string, not an array).

Parameters

string $path

A path to the node to get

Return Value

mixed

Array of matching data, or false on failure

See also

CldrParser
CldrModel::getRawData

mixed getElement(string $path)

Returns string value from a path given.

Path must point to leaf. Syntax for paths is same as for getRawData.

Parameters

string $path

A path to the element to get

Return Value

mixed

String with desired element, or false on failure

mixed findNodesWithinPath(string $path, string $nodeName)

Returns all nodes with given name found within given path

Parameters

string $path

A path to search in

string $nodeName

A name of the nodes to return

Return Value

mixed

String with desired element, or false on failure

static string getNodeName(string $nodeString)

Returns node name extracted from node string

The internal representation of CLDR uses array keys like: 'calendar[@type="gregorian"]' This method helps to extract the node name from such keys.

Parameters

string $nodeString

String with node name and optional attribute(s)

Return Value

string

Name of the node

static mixed getAttributeValue(string $nodeString, string $attributeName)

Parses the node string and returns a value of attribute for name provided.

An internal representation of CLDR data used by this class is a simple multi dimensional array where keys are nodes' names. If node has attributes, they are all stored as one string (e.g. 'calendar[@type="gregorian"]' or 'calendar[@type="gregorian"][@alt="proposed-x1001"').

This convenient method extracts a value of desired attribute by its name (in example above, in order to get the value 'gregorian', 'type' should be passed as the second parameter to this method).

Note: this method does not validate the input!

Parameters

string $nodeString

A node key to parse

string $attributeName

Name of the attribute to find

Return Value

mixed

Value of desired attribute, or false if there is no such attribute

protected array parseFiles(array $sourcePaths)

Parses given CLDR files using CldrParser and merges parsed data.

Merging is done with inheritance in mind, as defined in CLDR specification.

Parameters

array $sourcePaths

Absolute paths to CLDR files (can be one file)

Return Value

array

Parsed and merged data

protected array mergeTwoParsedFiles(mixed $firstParsedData, mixed $secondParsedData)

Merges two sets of data from two separate CLDR files into one array.

Merging is done with inheritance in mind, as defined in CLDR specification.

Parameters

mixed $firstParsedData

Part of data from first file (either array or string)

mixed $secondParsedData

Part of data from second file (either array or string)

Return Value

array

Data merged from two files

protected mixed resolveAliases(mixed $data, string $currentPath)

Resolves any 'alias' nodes in parsed CLDR data.

CLDR uses 'alias' tag which denotes places where data should be copied from. This tag has 'source' attribute pointing (by relative XPath query) to the source node - it should be copied with all it's children.

Parameters

mixed $data

Part of internal array to resolve aliases for (string if leaf, array otherwise)

string $currentPath

Path to currently analyzed part of data

Return Value

mixed

Modified (or unchanged) $data

Exceptions

InvalidCldrDataException