1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 14:16:46 +02:00

feat(directives): add string type for @type directive

This commit is contained in:
Awilum
2022-05-16 14:04:07 +03:00
parent 94db7b20a9
commit 7708d60f75
2 changed files with 4 additions and 0 deletions

View File

@@ -57,6 +57,8 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void {
} else {
$field['value'] = collectionFromQueryString($field['value']->toString());
}
} elseif (strings($field['value'])->contains('@type(string)')) {
$field['value'] = (string) $field['value'];
} elseif (strings($field['value'])->contains('@type(null)')) {
$field['value'] = null;
}

View File

@@ -22,6 +22,7 @@ test('types directive', function () {
entries()->create('type-array-4', ['foo' => '@type(array) foo']);
entries()->create('type-collection', ['foo' => '@type(collection) foo']);
entries()->create('type-null', ['foo' => '@type(null) foo']);
entries()->create('type-string', ['foo' => '@type(string) foo']);
entries()->create('type-json', ['foo' => '@type(json) foo=Foo']);
entries()->create('type-json-2', ['foo' => '@type(json) {"foo": "Foo"}']);
entries()->create('type-json-3', ['foo' => '@type(json) [1,2,3,4,5]']);
@@ -36,6 +37,7 @@ test('types directive', function () {
$this->assertEquals(['foo' => 'Foo'], entries()->fetch('type-array-3')['foo']);
$this->assertEquals(['foo' => ''], entries()->fetch('type-array-4')['foo']);
$this->assertEquals(null, entries()->fetch('type-null')['foo']);
$this->assertEquals('foo', entries()->fetch('type-string')['foo']);
$this->assertEquals('{"foo":"Foo"}', entries()->fetch('type-json')['foo']);
$this->assertEquals('{"foo": "Foo"}', entries()->fetch('type-json-2')['foo']);
$this->assertEquals('[1,2,3,4,5]', entries()->fetch('type-json-3')['foo']);