#3343522 Move the "do not override" variables into a separate file
Closes #3343522
Merge request reports
Activity
added 5 commits
-
b0cf0ca6...d10995a4 - 4 commits from branch
project:main
- 43c7a703 - Merge branch 'main' into 3343522-hide-variables
-
b0cf0ca6...d10995a4 - 4 commits from branch
333 333 continue; 334 334 } 335 335 336 // Remaining lines are either values or the name of the variables. 336 // Remaining lines are either the name of the variable, the value or both. 337 337 if (strpos($line, 'value:') === 0) { 338 338 // Remove 'value:' and all quotes. 339 339 $values[$last_name] = trim(str_replace(['value:', '"', "'"], ['', '', ''], $line)); 340 340 } 341 341 else { 342 342 $last_name = trim($line, ':'); 343 // If the line contains the name and a value then get both. 344 $name_and_value = explode(':', $line); 345 if ($name_and_value[1] != '') { changed this line in version 5 of the diff
I could not make it fail with how the code was before. Even if there is no value, the format of the variables file requires
:
after the name. So theexplode
would alway create a second array item. It would only give aPHP Warning: Undefined array key 1
if we had got the format of the file wrong. So the old way would actually alert to an error in the file.Edited by Jonathan SmithI think the logic is that if we have:
variables: _NAME: value: "..." description: "..."
The first interaction of the loop will capture
_NAME
under$last_name
and then the next iteration capturesvalue:
and sets that value under$values[$last_name]
.So the second part of that explode could be totally empty in the example above if we load the
variables.yml
file. The reason why it might not fail is because we are now loading thehidden-variables.yml
file, but I'd rather have the logic support both, which I think it does.I wasn't sure if it'd create the empty array element, that's why I added the
!empty
Yes we do get the empty second element when the
$line
just containssomething:
It worked for both styles of syntax the way I had it, I have tested that. The new bit
$name_and_value = explode(':', $line)
is done in theelse
which is when the line does not start withvalue:
so it is only the lines which havethe_name: something
or justthe_name:
which are processed here. In either case, we do get the second array item.But using
!empty
is nicer. It won't fail for invalid yml syntax, i.e. if the:
was missing, which the previous version did fail on. But we'd soon find out if we missed a : in the file. So let's leave as is.