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

Commit 6ea8648

Browse files
committed
Allowing null values to be used inline.
1 parent f64f86c commit 6ea8648

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/lib/Herrera/Wise/Loader/AbstractFileLoader.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ function (&$value) use (&$data, $global, $_this) {
145145
$ref = $_this->resolveReference($reference, $global);
146146
}
147147

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

157+
if ("%$reference%" === $value) {
156158
$value = $ref;
157159
} else {
158160
$value = str_replace("%$reference%", $ref, $value);

src/tests/Herrera/Wise/Tests/Loader/AbstractFileLoaderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testProcess()
124124
),
125125
'global' => '%global.value%',
126126
'placeholder' => '%imported.list%',
127-
'inline_placeholder' => 'rand: %imported.value%'
127+
'inline_placeholder' => 'rand: %imported.list.null%%imported.value%'
128128
),
129129
true
130130
) . ';'
@@ -136,6 +136,7 @@ public function testProcess()
136136
array(
137137
'imported' => array(
138138
'list' => array(
139+
'null' => null,
139140
'value' => 123
140141
),
141142
'value' => $rand = rand()
@@ -154,11 +155,13 @@ public function testProcess()
154155
),
155156
'global' => 999,
156157
'placeholder' => array(
158+
'null' => null,
157159
'value' => 123
158160
),
159161
'inline_placeholder' => 'rand: ' . $rand,
160162
'imported' => array(
161163
'list' => array(
164+
'null' => null,
162165
'value' => 123
163166
),
164167
'value' => $rand

0 commit comments

Comments
 (0)