Skip to content

Commit

Permalink
Add possibility to browse injected var with %myvar.path% (not only fo…
Browse files Browse the repository at this point in the history
…r browse current yaml file)
  • Loading branch information
ArthurHlt committed Mar 14, 2015
1 parent d24284a commit f603c80
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions src/Arhframe/Yamlarh/Yamlarh.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,60 @@ public function insertVar($value, &$arrayToReturn, $completeArray)
foreach ($varArray as $var) {
$finalVar = $finalVar[$var];
}
if (empty($finalVar)) {
$finalVar = $this->getVar($varArray, $arrayToReturn);
}
$startValue = preg_replace('#%' . preg_quote($value) . '%#', $finalVar, $startValue);

continue;
}
$var = $arrayToReturn[$value];
global $$value;
$varFromFile = $$value;
if (!empty($varFromFile)) {
$var = $varFromFile;
}
if (defined($value)) {
$var = constant($value);
}
if (!empty($this->accessibleVariable[$value])) {
$var = $this->accessibleVariable[$value];
}
$var = $this->getVar($value, $arrayToReturn);
$startValue = preg_replace('#%' . preg_quote($value) . '%#', $var, $startValue);
}

return $startValue;
}

private function getVar($value, &$arrayToReturn)
{
$allValues = null;
if (is_array($value)) {
$allValues = $value;
$value = $value[0];
}
$var = $arrayToReturn[$value];
global $$value;
$varFromFile = $$value;
if (!empty($varFromFile)) {
$var = $varFromFile;
}
if (defined($value)) {
$var = constant($value);
}
if (!empty($this->accessibleVariable[$value])) {
$var = $this->accessibleVariable[$value];
}

$var = $this->getComplexeVar($var, $allValues);
return $var;
}

private function getComplexeVar($var, $values)
{
if (empty($values)) {
return $var;
}
$values = array_slice($values, 1);
if (is_object($var) && !empty($values)) {
$get = "get" . ucfirst($values[0]);
return $this->getComplexeVar($var->$get(), $values);
}
if (is_array($var) && !empty($values)) {
return $this->getComplexeVar($var[$values[0]], $values);
}
return $var;
}

private function parseFile($file)
{
$parsedYml = Yaml::parse($file->getContent());
Expand Down

0 comments on commit f603c80

Please sign in to comment.