1 [![Build Status](https://travis-ci.org/grasmash/expander.svg?branch=master)](https://travis-ci.org/grasmash/expander) [![Packagist](https://img.shields.io/packagist/v/grasmash/expander.svg)](https://packagist.org/packages/grasmash/expander)
2 [![Total Downloads](https://poser.pugx.org/grasmash/expander/downloads)](https://packagist.org/packages/grasmash/expander) [![Coverage Status](https://coveralls.io/repos/github/grasmash/expander/badge.svg?branch=master)](https://coveralls.io/github/grasmash/expander?branch=master)
4 This tool expands property references in PHP arrays. For example implementation, see Yaml Expander.
8 composer require grasmash/expander
12 Property references use dot notation to indicate array keys, and must be wrapped in `${}`.
23 'author' => 'Frank Herbert',
24 'copyright' => '${book.author} 1965',
25 'protaganist' => '${characters.0.name}',
30 'nested-reference' => '${book.sequel}',
34 'name' => 'Paul Atreides',
35 'occupation' => 'Kwisatz Haderach',
43 'name' => 'Duncan Idaho',
44 'occupation' => 'Swordmaster',
47 'summary' => '${book.title} by ${book.author}',
48 'publisher' => '${not.real.property}',
49 'sequels' => '${book.sequel}, and others.',
50 'available-products' => '${book.media.1}, ${book.media.0}',
51 'product-name' => '${${type}.title}',
52 'boolean-value' => true,
59 'expand-array' => '${inline-array}',
60 'env-test' => '${env.test}',
63 $expander = new Expander();
64 // Optionally set a logger.
65 $expander->setLogger(new Psr\Log\NullLogger());
66 // Optionally set a Stringfier, used to convert array placeholders into strings. Defaults to using implode() with `,` delimeter.
67 // @see StringifierInterface.
68 $expander->setStringifier(new Grasmash\Expander\Stringifier());
70 // Parse an array, expanding internal property references.
71 $expanded = $expander->expandArrayProperties($array);
73 // Parse an array, expanding references using both internal and supplementary values.
74 $reference_properties = 'book' => ['sequel' => 'Dune Messiah'];
75 // Set an environmental variable.
76 putenv("test=gomjabbar");
77 $expanded = $expander->expandArrayProperties($array, $reference_properties);
91 [author] => Frank Herbert
92 [copyright] => Frank Herbert 1965
93 [protaganist] => Paul Atreides
100 [nested-reference] => Dune Messiah
103 [characters] => Array
107 [name] => Paul Atreides
108 [occupation] => Kwisatz Haderach
120 [name] => Duncan Idaho
121 [occupation] => Swordmaster
126 [summary] => Dune by Frank Herbert
127 [publisher] => ${not.real.property}
128 [sequels] => Dune Messiah, and others.
129 [available-products] => paperback, hardcover
130 [product-name] => Dune
133 [inline-array] => Array
140 [expand-array] => one,two,three
141 [env-test] => gomjabbar