Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Commit

Permalink
Allowing null values to be used inline.
Browse files Browse the repository at this point in the history
  • Loading branch information
kherge committed Jul 12, 2013
1 parent f64f86c commit 6ea8648
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/lib/Herrera/Wise/Loader/AbstractFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ function (&$value) use (&$data, $global, $_this) {
$ref = $_this->resolveReference($reference, $global);
}

if (false === is_scalar($ref)) {
if (false == preg_match('/^%(?:[^%]+)%$/', $value)) {
throw InvalidReferenceException::format(
'The non-scalar reference "%s" cannot be used inline.',
"%$reference%"
);
}
if ((false === is_null($ref))
&& (false === is_scalar($ref))
&& (false == preg_match('/^%(?:[^%]+)%$/', $value))) {
throw InvalidReferenceException::format(
'The non-scalar reference "%s" cannot be used inline.',
"%$reference%"
);
}

if ("%$reference%" === $value) {
$value = $ref;
} else {
$value = str_replace("%$reference%", $ref, $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testProcess()
),
'global' => '%global.value%',
'placeholder' => '%imported.list%',
'inline_placeholder' => 'rand: %imported.value%'
'inline_placeholder' => 'rand: %imported.list.null%%imported.value%'
),
true
) . ';'
Expand All @@ -136,6 +136,7 @@ public function testProcess()
array(
'imported' => array(
'list' => array(
'null' => null,
'value' => 123
),
'value' => $rand = rand()
Expand All @@ -154,11 +155,13 @@ public function testProcess()
),
'global' => 999,
'placeholder' => array(
'null' => null,
'value' => 123
),
'inline_placeholder' => 'rand: ' . $rand,
'imported' => array(
'list' => array(
'null' => null,
'value' => 123
),
'value' => $rand
Expand Down

0 comments on commit 6ea8648

Please sign in to comment.