5 * @link http://php-di.org/
6 * @copyright Matthieu Napoli (http://mnapoli.fr/)
7 * @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
10 namespace DI\Definition\Dumper;
13 use DI\Definition\ArrayDefinition;
14 use DI\Definition\Definition;
15 use DI\Definition\Helper\DefinitionHelper;
18 * Dumps array definitions.
21 * @author Matthieu Napoli <matthieu@mnapoli.fr>
23 class ArrayDefinitionDumper implements DefinitionDumper
28 public function dump(Definition $definition)
30 if (! $definition instanceof ArrayDefinition) {
31 throw new \InvalidArgumentException(sprintf(
32 'This definition dumper is only compatible with ArrayDefinition objects, %s given',
33 get_class($definition)
39 foreach ($definition->getValues() as $key => $value) {
40 if (is_string($key)) {
41 $key = "'" . $key . "'";
44 $str .= ' ' . $key . ' => ';
46 if ($value instanceof DefinitionHelper) {
47 $nestedDefinition = Debug::dumpDefinition($value->getDefinition(''));
48 $str .= $this->indent($nestedDefinition);
50 $str .= var_export($value, true);
53 $str .= ',' . PHP_EOL;
61 private function indent($str)
63 return str_replace(PHP_EOL, PHP_EOL . " ", $str);