CldrModel
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
Contructs the model
When it's called, CLDR file is parsed or cache is loaded, if available.
Returns multi-dimensional array representing desired node and it's children, or a string value if the path points to a leaf.
Returns multi-dimensional array representing desired node and it's children.
Returns string value from a path given.
Returns all nodes with given name found within given path
Returns node name extracted from node string
Parses the node string and returns a value of attribute for name provided.
Parses given CLDR files using CldrParser and merges parsed data.
Merges two sets of data from two separate CLDR files into one array.
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).
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.
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.
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).
mixed
getElement(string $path)
Returns string value from a path given.
Path must point to leaf. Syntax for paths is same as for getRawData.
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
The internal representation of CLDR uses array keys like: 'calendar[@type="gregorian"]' This method helps to extract the node name from such keys.
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!
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.
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.
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.