PHP Class Neos\Flow\I18n\Cldr\CldrModel

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.
Exibir arquivo Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$cache Neos\Cache\Frontend\VariableFrontend
$cacheKey string Key used to store / retrieve cached data
$cldrBasePath string An absolute path to the directory where CLDR resides. It is changed only in tests.
$cldrParser CldrParser
$parsedData array
$sourcePaths array Absolute path or path to the files represented by this class' instance.

Public Methods

Method Description
__construct ( array $sourcePaths ) Contructs the model
findNodesWithinPath ( string $path, string $nodeName ) : mixed Returns all nodes with given name found within given path
getAttributeValue ( string $nodeString, string $attributeName ) : mixed Parses the node string and returns a value of attribute for name provided.
getElement ( string $path ) : mixed Returns string value from a path given.
getNodeName ( string $nodeString ) : string Returns node name extracted from node string
getRawArray ( string $path ) : mixed Returns multi-dimensional array representing desired node and it's children.
getRawData ( string $path ) : mixed Returns multi-dimensional array representing desired node and it's children, or a string value if the path points to a leaf.
initializeObject ( ) : void When it's called, CLDR file is parsed or cache is loaded, if available.
injectCache ( Neos\Cache\Frontend\VariableFrontend $cache ) : void Injects the Flow_I18n_Cldr_CldrModelCache cache
injectParser ( CldrParser $parser ) : void

Protected Methods

Method Description
mergeTwoParsedFiles ( mixed $firstParsedData, mixed $secondParsedData ) : array Merges two sets of data from two separate CLDR files into one array.
parseFiles ( array $sourcePaths ) : array Parses given CLDR files using CldrParser and merges parsed data.
resolveAliases ( mixed $data, string $currentPath ) : mixed Resolves any 'alias' nodes in parsed CLDR data.

Method Details

__construct() public method

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).
public __construct ( array $sourcePaths )
$sourcePaths array

findNodesWithinPath() public method

Returns all nodes with given name found within given path
public findNodesWithinPath ( string $path, string $nodeName ) : mixed
$path string A path to search in
$nodeName string A name of the nodes to return
return mixed String with desired element, or FALSE on failure

getAttributeValue() public static method

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!
public static getAttributeValue ( string $nodeString, string $attributeName ) : mixed
$nodeString string A node key to parse
$attributeName string Name of the attribute to find
return mixed Value of desired attribute, or FALSE if there is no such attribute

getElement() public method

Path must point to leaf. Syntax for paths is same as for getRawData.
public getElement ( string $path ) : mixed
$path string A path to the element to get
return mixed String with desired element, or FALSE on failure

getNodeName() public static method

The internal representation of CLDR uses array keys like: 'calendar[@type="gregorian"]' This method helps to extract the node name from such keys.
public static getNodeName ( string $nodeString ) : string
$nodeString string String with node name and optional attribute(s)
return string Name of the node

getRawArray() public method

This method will return FALSE if the path points to a leaf (i.e. a string, not an array).
See also: CldrParser
See also: CldrModel::getRawData()
public getRawArray ( string $path ) : mixed
$path string A path to the node to get
return mixed Array of matching data, or FALSE on failure

getRawData() public method

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.
See also: CldrParser
public getRawData ( string $path ) : mixed
$path string A path to the node to get
return mixed Array or string of matching data, or FALSE on failure

initializeObject() public method

When it's called, CLDR file is parsed or cache is loaded, if available.
public initializeObject ( ) : void
return void

injectCache() public method

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

injectParser() public method

public injectParser ( CldrParser $parser ) : void
$parser CldrParser
return void

mergeTwoParsedFiles() protected method

Merging is done with inheritance in mind, as defined in CLDR specification.
protected mergeTwoParsedFiles ( mixed $firstParsedData, mixed $secondParsedData ) : array
$firstParsedData mixed Part of data from first file (either array or string)
$secondParsedData mixed Part of data from second file (either array or string)
return array Data merged from two files

parseFiles() protected method

Merging is done with inheritance in mind, as defined in CLDR specification.
protected parseFiles ( array $sourcePaths ) : array
$sourcePaths array
return array Parsed and merged data

resolveAliases() protected method

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.
protected resolveAliases ( mixed $data, string $currentPath ) : mixed
$data mixed Part of internal array to resolve aliases for (string if leaf, array otherwise)
$currentPath string Path to currently analyzed part of data
return mixed Modified (or unchanged) $data

Property Details

$cache protected_oe property

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

$cacheKey protected_oe property

Key used to store / retrieve cached data
protected string $cacheKey
return string

$cldrBasePath protected_oe property

An absolute path to the directory where CLDR resides. It is changed only in tests.
protected string $cldrBasePath
return string

$cldrParser protected_oe property

protected CldrParser,Neos\Flow\I18n\Cldr $cldrParser
return CldrParser

$parsedData protected_oe property

protected array $parsedData
return array

$sourcePaths protected_oe property

Absolute path or path to the files represented by this class' instance.
protected array $sourcePaths
return array