Skip to content

Commit 12bbb0e

Browse files
sallyxdg
authored andcommitted
Encoder: added support for entity chaining [Closes #21]
1 parent 48b25e0 commit 12bbb0e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Neon/Encoder.php

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public function encode($var, $options = NULL)
2828
return $var->format('Y-m-d H:i:s O');
2929

3030
} elseif ($var instanceof Entity) {
31+
if ($var->value === Neon::CHAIN) {
32+
return implode('', array_map(array($this, 'encode'), $var->attributes));
33+
}
3134
return $this->encode($var->value) . '('
3235
. (is_array($var->attributes) ? substr($this->encode($var->attributes), 1, -1) : '') . ')';
3336
}

tests/Neon/Encoder.phpt

+9
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,12 @@ Assert::same(
8282
"foo: 1\nbar:\n\tx:\n\t\t- 1\n\t\t- 2\n\n\ty:\n\t\t- 3\n\t\t- 4\n\nbaz: null\n",
8383
Neon::encode(array('foo' => 1, 'bar' => array('x' => array(1, 2), 'y' => array(3, 4)), 'baz' => NULL), Neon::BLOCK)
8484
);
85+
86+
Assert::same(
87+
'ent(1)inner(2, 3)',
88+
Neon::encode(Neon::decode('ent(1)inner(2, 3)'))
89+
);
90+
Assert::same(
91+
'foo(1, 2)::bar(3)',
92+
Neon::encode(Neon::decode('foo(1,2)::bar(3)'))
93+
);

0 commit comments

Comments
 (0)