Skip to content

Propose: {{XXX}} and ref->XXX in any data files #110

Open
@asbeseda

Description

@asbeseda

At first, thanks for good framework, it very useful for me...

Propose to add a support of patterns in data.yaml and references to other data like this
In data.yaml:

testA: 
  testB: BBBBB
testABByPattern: "{{testA.testB}}" #don't forgot "
testAByReference: ref->testA

I already realise this for my project. It useful for me in many cases :). Here is a code:
at pattern-lab\core\src\PatternLab\PatternData\Helpers\PatternCodeHelper.php add at run() function

$data = Data::getPatternSpecificData($patternStoreKey);
	
/* ADDITION by asbeseda@mail.ru */
$this->myAdditionalProcessData($data, $patternLoader);

And new functions defenitions.....

/* ADDITION-BEGIN by asbeseda@mail.ru */
private function myAdditionalProcessDataRecursive($path, &$dataCurrentLevel, &$dataAll, $patternLoader, &$dataByPath){
	if(is_array($dataCurrentLevel)){
		foreach ($dataCurrentLevel as $nextKey => $nextValue) {
			$nextPath = $path . ((empty($path))?"":".") . $nextKey;
			$nextValue = $this->myAdditionalProcessDataRecursive($nextPath, $nextValue, $dataAll, $patternLoader, $dataByPath);
			$dataCurrentLevel[$nextKey] = $nextValue; 
		}
	} else if(is_string($dataCurrentLevel)) {
		if(strpos($dataCurrentLevel, '{{') !== false)
			$dataCurrentLevel = $patternLoader->render(array("pattern" => $dataCurrentLevel, "data" => $dataAll));
		if(strpos($dataCurrentLevel, 'ref->') !== false){
			$dataCurrentLevel = $dataByPath[str_replace("ref->","",$dataCurrentLevel)];
		}
	}
	if(!empty($path))
		$dataByPath[$path] = $dataCurrentLevel;
	return $dataCurrentLevel;
}
private function myAdditionalProcessData(&$patternData, $patternLoader){
	$dataByPath = Array();
	$this->myAdditionalProcessDataRecursive("", $patternData, $patternData, $patternLoader, $dataByPath);
}
/* ADDITION-END by asbeseda@mail.ru  */

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions