diff --git a/src/flextype/core/Entries/Directives/CalcDirective.php b/src/flextype/core/Entries/Directives/CalcDirective.php index a22dfbd5..cc4f67cc 100644 --- a/src/flextype/core/Entries/Directives/CalcDirective.php +++ b/src/flextype/core/Entries/Directives/CalcDirective.php @@ -28,7 +28,7 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $result = entries()->registry()->get('methods.fetch.result'); if (is_string($field['value'])) { - $field['value'] = preg_replace_callback('/@calc\((.*?)\)/s', function($matches) use ($result) { + $field['value'] = preg_replace_callback('/@calc\[(.*?)\]/s', function($matches) use ($result) { return (new StringCalc())->calculate($matches[1]); }, $field['value']); } diff --git a/src/flextype/core/Entries/Directives/ConstantsDirective.php b/src/flextype/core/Entries/Directives/ConstantsDirective.php index 93d1713a..e7da0176 100644 --- a/src/flextype/core/Entries/Directives/ConstantsDirective.php +++ b/src/flextype/core/Entries/Directives/ConstantsDirective.php @@ -27,8 +27,8 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { if (is_string($field['value'])) { $field['value'] = strings($field['value']) - ->replace('@const(ROOT_DIR)', ROOT_DIR) - ->replace('@const(PATH_PROJECT)', PATH['project']) + ->replace('@const[ROOT_DIR]', ROOT_DIR) + ->replace('@const[PATH_PROJECT]', PATH['project']) ->toString(); } diff --git a/src/flextype/core/Entries/Directives/FieldsDirective.php b/src/flextype/core/Entries/Directives/FieldsDirective.php index 8e071ea3..4f5bb69d 100644 --- a/src/flextype/core/Entries/Directives/FieldsDirective.php +++ b/src/flextype/core/Entries/Directives/FieldsDirective.php @@ -27,7 +27,7 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $result = entries()->registry()->get('methods.fetch.result'); if (is_string($field['value'])) { - $field['value'] = preg_replace_callback('/@field\((.*?)\)/s', function($matches) use ($result) { + $field['value'] = preg_replace_callback('/@field\[(.*?)\]/s', function($matches) use ($result) { return collection($result)->get($matches[1]); }, $field['value']); } diff --git a/src/flextype/core/Entries/Directives/TypesDirective.php b/src/flextype/core/Entries/Directives/TypesDirective.php index da4b7feb..0719ce8a 100644 --- a/src/flextype/core/Entries/Directives/TypesDirective.php +++ b/src/flextype/core/Entries/Directives/TypesDirective.php @@ -16,7 +16,7 @@ declare(strict_types=1); use Glowy\Arrays\Arrays as Collection; -// Directive: @type() +// Directive: @type[) emitter()->addListener('onEntriesFetchSingleField', static function (): void { if (! registry()->get('flextype.settings.entries.directives.types.enabled')) { @@ -26,40 +26,40 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $field = entries()->registry()->get('methods.fetch.field'); if (is_string($field['value'])) { - if (strings($field['value'])->contains('@type(integer)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(integer)', '')->trim())->toInteger(); - } elseif (strings($field['value'])->contains('@type(int)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(int)', '')->trim())->toInteger(); - } elseif (strings($field['value'])->contains('@type(float)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(float)', '')->trim())->toFloat(); - } elseif (strings($field['value'])->contains('@type(boolean)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(boolean)', '')->trim())->toBoolean(); - } elseif (strings($field['value'])->contains('@type(bool)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(bool)', '')->trim())->toBoolean(); - } elseif (strings($field['value'])->contains('@type(json)')) { - $field['value'] = strings($field['value'])->replace('@type(json)', '')->trim(); + if (strings($field['value'])->contains('@type[integer]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[integer]', '')->trim())->toInteger(); + } elseif (strings($field['value'])->contains('@type[int]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[int]', '')->trim())->toInteger(); + } elseif (strings($field['value'])->contains('@type[float]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[float]', '')->trim())->toFloat(); + } elseif (strings($field['value'])->contains('@type[boolean]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[boolean]', '')->trim())->toBoolean(); + } elseif (strings($field['value'])->contains('@type[bool]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[bool]', '')->trim())->toBoolean(); + } elseif (strings($field['value'])->contains('@type[json]')) { + $field['value'] = strings($field['value'])->replace('@type[json]', '')->trim(); if (strings($field['value'])->isJson()) { $field['value'] = $field['value']; } else { $field['value'] = collectionFromQueryString($field['value']->toString())->toJson(); } - } elseif (strings($field['value'])->contains('@type(array)')) { - $field['value'] = strings($field['value'])->replace('@type(array)', '')->trim(); + } elseif (strings($field['value'])->contains('@type[array]')) { + $field['value'] = strings($field['value'])->replace('@type[array]', '')->trim(); if (strings($field['value'])->isJson()) { $field['value'] = serializers()->json()->decode($field['value']->toString()); } else { $field['value'] = collectionFromQueryString($field['value']->toString())->toArray(); } - } elseif (strings($field['value'])->contains('@type(collection)')) { - $field['value'] = strings($field['value'])->replace('@type(collection)', '')->trim(); + } elseif (strings($field['value'])->contains('@type[collection]')) { + $field['value'] = strings($field['value'])->replace('@type[collection]', '')->trim(); if (strings($field['value'])->isJson()) { $field['value'] = collection(serializers()->json()->decode($field['value']->toString())); } else { $field['value'] = collectionFromQueryString($field['value']->toString()); } - } elseif (strings($field['value'])->contains('@type(string)')) { - $field['value'] = strings(strings($field['value'])->replace('@type(string)', '')->trim())->toString(); - } elseif (strings($field['value'])->contains('@type(null)')) { + } elseif (strings($field['value'])->contains('@type[string]')) { + $field['value'] = strings(strings($field['value'])->replace('@type[string]', '')->trim())->toString(); + } elseif (strings($field['value'])->contains('@type[null]')) { $field['value'] = null; } } diff --git a/src/flextype/core/Entries/Directives/VarsDirective.php b/src/flextype/core/Entries/Directives/VarsDirective.php index 0a406ea5..d857d237 100644 --- a/src/flextype/core/Entries/Directives/VarsDirective.php +++ b/src/flextype/core/Entries/Directives/VarsDirective.php @@ -27,8 +27,8 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $result = entries()->registry()->get('methods.fetch.result'); if (is_string($field['value'])) { - $field['value'] = preg_replace_callback('/@var\((.*?)\)/s', function($matches) use ($result) { - return collection($result['vars'])->get($matches[1]); + $field['value'] = preg_replace_callback('/@var\[(.*?)\]/s', function($matches) use ($result) { + return collection($result['vars'])->get(trim($matches[1])); }, $field['value']); } diff --git a/tests/src/flextype/core/Entries/Directives/CalcDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/CalcDirectiveTest.php index d1fa3257..21f12a3d 100644 --- a/tests/src/flextype/core/Entries/Directives/CalcDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/CalcDirectiveTest.php @@ -11,6 +11,7 @@ afterEach(function (): void { }); test('calc directive', function () { - entries()->create('field', ['foo' => '@calc(2+2)']); + // (calc:1+1) + entries()->create('field', ['foo' => '@calc[2+2]']); $this->assertEquals(4, entries()->fetch('field')['foo']); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Directives/ConstantsDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/ConstantsDirectiveTest.php index d4ae28c7..27789357 100644 --- a/tests/src/flextype/core/Entries/Directives/ConstantsDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/ConstantsDirectiveTest.php @@ -11,8 +11,8 @@ afterEach(function (): void { }); test('constants directive', function () { - entries()->create('const-root-dir', ['path' => '@const(ROOT_DIR)']); - entries()->create('const-root-dir-2', ['path' => '@const(PATH_PROJECT)']); + entries()->create('const-root-dir', ['path' => '@const[ROOT_DIR]']); + entries()->create('const-root-dir-2', ['path' => '@const[PATH_PROJECT]']); $this->assertEquals(ROOT_DIR, entries()->fetch('const-root-dir')['path']); $this->assertEquals(PATH['project'], entries()->fetch('const-root-dir-2')['path']); diff --git a/tests/src/flextype/core/Entries/Directives/FieldsDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/FieldsDirectiveTest.php index 5bbbdde4..2b71415c 100644 --- a/tests/src/flextype/core/Entries/Directives/FieldsDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/FieldsDirectiveTest.php @@ -11,6 +11,6 @@ afterEach(function (): void { }); test('fields directive', function () { - entries()->create('field', ['foo' => '@field(id)']); + entries()->create('field', ['foo' => '@field[id]']); $this->assertEquals('field', entries()->fetch('field')['foo']); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Directives/ShortcodesDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/ShortcodesDirectiveTest.php index 423da246..4d7c4800 100644 --- a/tests/src/flextype/core/Entries/Directives/ShortcodesDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/ShortcodesDirectiveTest.php @@ -11,7 +11,7 @@ afterEach(function (): void { }); test('shortcodes directive', function () { - entries()->create('shortcodes', ['foo' => '@shortcodes [strings prepend="Hello "]World[/strings]']); + entries()->create('shortcodes', ['foo' => '@shortcodes (strings prepend:"Hello ")World(/strings)']); $this->assertEquals('Hello World', entries()->fetch('shortcodes')['foo']); }); \ No newline at end of file diff --git a/tests/src/flextype/core/Entries/Directives/TypesDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/TypesDirectiveTest.php index ca6ba53d..76f776c4 100644 --- a/tests/src/flextype/core/Entries/Directives/TypesDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/TypesDirectiveTest.php @@ -11,21 +11,21 @@ afterEach(function (): void { }); test('types directive', function () { - entries()->create('type-int', ['foo' => '@type(int) 100']); - entries()->create('type-integer', ['foo' => '@type(integer) 100']); - entries()->create('type-bool', ['foo' => '@type(bool) true']); - entries()->create('type-boolean', ['foo' => '@type(boolean) false']); - entries()->create('type-float', ['foo' => '@type(float) 1.5']); - entries()->create('type-array', ['foo' => '@type(array) foo=bar']); - entries()->create('type-array-2', ['foo' => '@type(array) [1,2,3,4,5]']); - entries()->create('type-array-3', ['foo' => '@type(array) {"foo": "Foo"}']); - 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]']); + entries()->create('type-int', ['foo' => '@type[int] 100']); + entries()->create('type-integer', ['foo' => '@type[integer] 100']); + entries()->create('type-bool', ['foo' => '@type[bool] true']); + entries()->create('type-boolean', ['foo' => '@type[boolean] false']); + entries()->create('type-float', ['foo' => '@type[float] 1.5']); + entries()->create('type-array', ['foo' => '@type[array] foo=bar']); + entries()->create('type-array-2', ['foo' => '@type[array] [1,2,3,4,5]']); + entries()->create('type-array-3', ['foo' => '@type[array] {"foo": "Foo"}']); + 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]']); $this->assertEquals(100, entries()->fetch('type-int')['foo']); $this->assertEquals(100, entries()->fetch('type-integer')['foo']); diff --git a/tests/src/flextype/core/Entries/Directives/VarsDirectiveTest.php b/tests/src/flextype/core/Entries/Directives/VarsDirectiveTest.php index 8716b1f3..4c0917c1 100644 --- a/tests/src/flextype/core/Entries/Directives/VarsDirectiveTest.php +++ b/tests/src/flextype/core/Entries/Directives/VarsDirectiveTest.php @@ -11,7 +11,7 @@ afterEach(function (): void { }); test('vars directive', function () { - entries()->create('type-vars', ['vars' => ['foo' => 'Foo'], 'title' => '@var(foo)']); + entries()->create('type-vars', ['vars' => ['foo' => 'Foo'], 'title' => '@var[foo]']); $this->assertEquals('Foo', entries()->fetch('type-vars')['title']); }); \ No newline at end of file