Add nested Record types
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
4abd95f303
commit
a3bf698359
3 changed files with 18 additions and 5 deletions
|
|
@ -24,16 +24,20 @@ class ArrayType implements TypeInterface
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$subArray = isset($this->settings['subArray']) && $this->settings['subArray'];
|
if (isset($this->settings['isRecord']) && $this->settings['isRecord']) {
|
||||||
|
return new Record($this->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$subArray = isset($this->settings['isNestedArray']) && $this->settings['isNestedArray'];
|
||||||
|
|
||||||
array_walk($this->value, function (&$value, $key) {
|
array_walk($this->value, function (&$value, $key) {
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
$value = $key . ': ' . new Type($value, [
|
$value = $key . ': ' . new Type($value, [
|
||||||
'subArray' => is_array($value)
|
'isNestedArray' => is_array($value)
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$value = new Type($value, [
|
$value = new Type($value, [
|
||||||
'subArray' => is_array($value)
|
'isNestedArray' => is_array($value)
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,13 @@ class Record implements TypeInterface
|
||||||
{
|
{
|
||||||
array_walk($this->value, function (&$value, $key) {
|
array_walk($this->value, function (&$value, $key) {
|
||||||
if (is_string($key)) {
|
if (is_string($key)) {
|
||||||
$value = $key . ': ' . new Type($value);
|
$value = $key . ': ' . new Type($value, [
|
||||||
|
'isRecord' => true,
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
$value = new Type($value);
|
$value = new Type($value, [
|
||||||
|
'isRecord' => true,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ namespace Tests\Type;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Arendsen\FluxQueryBuilder\Type;
|
use Arendsen\FluxQueryBuilder\Type;
|
||||||
|
use Arendsen\FluxQueryBuilder\Type\Record;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
final class FactoryTypeTest extends TestCase
|
final class FactoryTypeTest extends TestCase
|
||||||
|
|
@ -59,6 +60,10 @@ final class FactoryTypeTest extends TestCase
|
||||||
['hello' => ['test' => 'bar', 'foo' => 'hi']],
|
['hello' => ['test' => 'bar', 'foo' => 'hi']],
|
||||||
'hello: [test: "bar", foo: "hi"]'
|
'hello: [test: "bar", foo: "hi"]'
|
||||||
],
|
],
|
||||||
|
'Record' => [
|
||||||
|
new Record(['foo' => 'bar', 'nested' => ['hello' => 'world']]),
|
||||||
|
'{foo: "bar", nested: {hello: "world"}}'
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue