Neos\Flow\I18n\Cldr\CldrModel::getAttributeValue PHP Метод

getAttributeValue() публичный статический Метод

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
Результат mixed Value of desired attribute, or FALSE if there is no such attribute
    public static function getAttributeValue($nodeString, $attributeName)
    {
        $attributeName = '[@' . $attributeName . '="';
        $positionOfAttributeName = strpos($nodeString, $attributeName);
        if ($positionOfAttributeName === false) {
            return false;
        }
        $positionOfAttributeValue = $positionOfAttributeName + strlen($attributeName);
        return substr($nodeString, $positionOfAttributeValue, strpos($nodeString, '"]', $positionOfAttributeValue) - $positionOfAttributeValue);
    }

Usage Example

 /**
  * @test
  */
 public function returnsAttributeValueCorrectly()
 {
     $sampleNodeString = 'dateFormatLength[@type="medium"][@alt="proposed"]';
     $this->assertEquals('medium', $this->model->getAttributeValue($sampleNodeString, 'type'));
     $this->assertEquals('proposed', $this->model->getAttributeValue($sampleNodeString, 'alt'));
     $this->assertEquals(false, $this->model->getAttributeValue($sampleNodeString, 'dateFormatLength'));
 }
All Usage Examples Of Neos\Flow\I18n\Cldr\CldrModel::getAttributeValue