Skip to content

Commit

Permalink
Adding support for expanding array placeholders.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Sep 26, 2017
1 parent 720c54b commit 983523c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Expander.php
Expand Up @@ -247,8 +247,8 @@ public static function expandProperty($property_name, $unexpanded_value, $data)
} else {
$expanded_value = $data->get($property_name);
if (is_array($expanded_value)) {
self::log("\${'$property_name'} is an array and cannot be expanded.");
return $unexpanded_value;
$expanded_value = Yaml::dump($expanded_value, 0);
return $expanded_value;
}
self::log("Expanding property \${'$property_name'} => $expanded_value.");
return $expanded_value;
Expand Down
5 changes: 1 addition & 4 deletions tests/phpunit/ExpanderTest.php
Expand Up @@ -27,14 +27,11 @@ public function testExpandArrayProperties($filename, $reference_array)
$this->assertEquals('Dune by Frank Herbert', $expanded['summary']);
$this->assertEquals('${book.media.1}, hardcover', $expanded['available-products']);
$this->assertEquals('Dune', $expanded['product-name']);
$this->assertEquals('${book}', $expanded['expand-array']);
$this->assertEquals(Yaml::dump($array['inline-array'], 0), $expanded['expand-array']);

$expanded = Expander::expandArrayProperties($array, $reference_array);
$this->assertEquals('Dune Messiah, and others.', $expanded['sequels']);
$this->assertEquals('Dune Messiah', $expanded['book']['nested-reference']);

// Attempt to expand an entire array. This should not work.
$this->assertEquals('${book}', $expanded['expand-array']);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/resources/valid.yml
Expand Up @@ -31,5 +31,4 @@ product-name: ${${type}.title}
boolean-value: true
null-value: null
inline-array: [ one, two, three ]
# Attempt to reference an entire array rather than a string. This is invalid.
expand-array: ${book}
expand-array: ${inline-array}

0 comments on commit 983523c

Please sign in to comment.