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

feat(expressions): add expressions engine support for entries fields

This commit is contained in:
Awilum
2022-05-28 21:33:20 +03:00
parent 045ef17372
commit da3b93b940
27 changed files with 993 additions and 1 deletions

View File

@@ -88,6 +88,7 @@
"victorjonsson/markdowndocs": "^1.3.8"
},
"config": {
"platform-check": false,
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true

View File

@@ -80,6 +80,7 @@ class Entries
$this->setRegistry($registry);
$this->setOptions($options);
$this->initExpressions(registry()->get('flextype.settings.entries.expressions'));
$this->initDirectives(registry()->get('flextype.settings.entries.directives'));
$this->initMacros(registry()->get('flextype.settings.entries.macros'));
$this->loadCollectionsEvents();
@@ -145,6 +146,38 @@ class Entries
}
}
/**
* Init Expressions
*
* @param array $expressions Expressions to init.
*
* @return void
*/
public function initExpressions(array $expressions): void
{
if (count($expressions) <= 0) {
return;
}
foreach ($expressions as $expression) {
if (! isset($expression['enabled'])) {
continue;
}
if (! $expression['enabled']) {
continue;
}
if (! strings($expression['class'])->endsWith('Expression')) {
continue;
}
if (class_exists($expression['class'])) {
expression()->registerProvider(new $expression['class']());
}
}
}
/**
* Load events for current collection.
*

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class ActionsExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('actions', fn() => 'actions()', fn($arguments) => actions())
];
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class CollectionExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('collection', fn($items = null) => 'collection($items)', fn($arguments, $items = null) => collection($items)),
new ExpressionFunction('collectionFromJson', fn(string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => 'collectionFromJson($input, $assoc, $depth, $flags)', fn($arguments, string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => collectionFromJson($input, $assoc, $depth, $flags)),
new ExpressionFunction('collectionFromString', fn(string $string, string $separator) => 'collectionFromString($string, $separator)', fn($arguments, string $string, string $separator) => collectionFromString($string, $separator)),
new ExpressionFunction('collectionWithRange', fn($low, $high, int $step = 1) => 'collection($low, $high, $step)', fn($arguments, $low, $high, int $step = 1) => collectionWithRange($low, $high, $step)),
new ExpressionFunction('collectionFromQueryString', fn(string $string) => 'collection($string)', fn($arguments, string $string) => collectionFromQueryString($string)),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class CsrfExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('csrf', fn() => '<input type="hidden" name="' . csrf()->getTokenName() . '" value="' . csrf()->getTokenValue() . '">', fn() => '<input type="hidden" name="' . csrf()->getTokenName() . '" value="' . csrf()->getTokenValue() . '">')
];
}
}

View File

@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Glowy\Arrays\Arrays as Collection;
use Glowy\Macroable\Macroable;
class EntriesExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('entries', fn() => '(new EntriesTwigExpressionsMethods())', fn($arguments) => (new EntriesTwigExpressionsMethods()))
];
}
}
class EntriesTwigExpressionsMethods
{
use Macroable;
/**
* Fetch.
*
* @param string $id Unique identifier of the entry.
* @param array $options Options array.
*
* @access public
*
* @return self Returns instance of The Arrays class.
*/
public function fetch(string $id, array $options = []): Collection
{
return entries()->fetch($id, $options);
}
/**
* Get Entries Registry.
*
* @return Collection Returns entries registry.
*
* @access public
*/
public function registry(): Collection
{
return entries()->registry();
}
/**
* Check whether entry exists
*
* @param string $id Unique identifier of the entry(entries).
*
* @return bool True on success, false on failure.
*
* @access public
*/
public function has(string $id): bool
{
return entries()->entries->has($id);
}
}

View File

@@ -0,0 +1,349 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
use Symfony\Component\Finder\Finder;
use Glowy\Arrays\Arrays as Collection;
use Glowy\Macroable\Macroable;
class FilesystemExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('filesystem', fn() => '(new FilesystemExpressionMethods())', fn($arguments) => (new FilesystemExpressionMethods()))
];
}
}
class FilesystemExpressionMethods
{
use Macroable;
/**
* Create a File instance.
*/
public function file($path): FilesystemFileExpressionMethods
{
return new FilesystemFileExpressionMethods($path);
}
/**
* Create a Directory instance.
*/
public function directory($path): FilesystemDirectoryExpressionMethods
{
return new FilesystemDirectoryExpressionMethods($path);
}
/**
* Create a Finder instance.
*/
public function find(): Finder
{
return filesystem()->find();
}
/**
* Determine if the given path is a stream path.
*
* @param string $path Path to check.
*
* @return bool Returns TRUE if the given path is stream path, FALSE otherwise.
*/
public function isStream(string $path): bool
{
return filesystem()->isStream($path);
}
/**
* Determine if the given path is absolute path.
*
* @param string $path Path to check.
*
* @return bool Returns TRUE if the given path is absolute path, FALSE otherwise.
*/
public function isAbsolute(string $path): bool
{
return filesystem()->isAbsolute($path);
}
/**
* Determine if the given path is a Windows path.
*
* @param string $path Path to check.
*
* @return bool true if windows path, false otherwise
*/
public function isWindowsPath(string $path): bool
{
return filesystem()->isWindowsPath($path);
}
/**
* Find path names matching a given pattern.
*
* @param string $pattern The pattern.
* @param int $flags Valid flags.
*
* @return array Returns an array containing the matched files/directories, an empty array if no file matched.
*/
public function glob(string $pattern, int $flags = 0): array
{
return filesystem()->glob($pattern, $flags);
}
}
class FilesystemFileExpressionMethods
{
use Macroable;
/**
* Path property
*
* Current file absolute path
*
* @var string|null
*/
public $path;
/**
* Constructor
*
* @param string $path Path to file.
*/
public function __construct(string $path)
{
$this->path = $path;
}
/**
* Get the contents of a file.
*
* @return string|false The file contents or false on failure.
*/
public function get()
{
return filesystem()->file($this->path)->get();
}
/**
* Checks the existence of file and returns false if any of them is missing.
*
* @return bool Returns true or false if any of them is missing.
*/
public function exists(): bool
{
return filesystem()->file($this->path)->exists();
}
/**
* Get the file's last modification time.
*
* @return int Returns the time the file was last modified.
*/
public function lastModified(): int
{
return filesystem()->file($this->path)->lastModified();
}
/**
* Get the file's last access time.
*
* @return int Returns the time the file was last assecc.
*/
public function lastAccess(): int
{
return filesystem()->file($this->path)->lastAccess();
}
/**
* Get the mime-type of a given file.
*
* @return string The mime-type of a given file.
*/
public function mimeType(): string
{
return filesystem()->file($this->path)->mimeType();
}
/**
* Get the file type of a given file.
*
* @return string The file type of a given file.
*/
public function type(): string
{
return filesystem()->file($this->path)->type();
}
/**
* Get the file extension from a file path.
*
* @return string The extension of a given file.
*/
public function extension(): string
{
return filesystem()->file($this->path)->extension();
}
/**
* Get the trailing name component from a file path.
*
* @return string The trailing name of a given file.
*/
public function basename(): string
{
return filesystem()->file($this->path)->basename();
}
/**
* Get the file name from a file path.
*
* @return string The file name of a given file.
*/
public function name(): string
{
return filesystem()->file($this->path)->name();
}
/**
* Return current path.
*
* @return string|null Current path
*/
public function path(): ?string
{
return filesystem()->file($this->path)->path();
}
/**
* Gets file size in bytes.
*
* @return int Returns the size of the file in bytes.
*/
public function size(): int
{
return filesystem()->file($this->path)->size();
}
/**
* Get the MD5 hash of the file at the given path.
*
* @return string Returns a string on success, FALSE otherwise.
*/
public function hash(): string
{
return filesystem()->file($this->path)->hash();
}
/**
* Determine if the given path is readable.
*
* @return bool Returns TRUE if the given path exists and is readable, FALSE otherwise.
*/
public function isReadable(): bool
{
return filesystem()->file($this->path)->isReadable();
}
/**
* Determine if the given path is writable.
*
* @return bool Returns TRUE if the given path exists and is writable, FALSE otherwise.
*/
public function isWritable(): bool
{
return filesystem()->file($this->path)->isWritable();
}
/**
* Determine if the given path is a regular file.
*
* @return bool Returns TRUE if the filename exists and is a regular file, FALSE otherwise.
*/
public function isFile(): bool
{
return filesystem()->file($this->path)->isFile();
}
}
class FilesystemDirectoryExpressionMethods
{
use Macroable;
/**
* Path property
*
* Current directory path.
*
* @var string|null
*/
public $path;
/**
* Constructor
*
* @param string $path Path to directory.
*/
public function __construct(string $path)
{
$this->path = $path;
}
/**
* Checks the existence of directory and returns false if any of them is missing.
*
* @return bool Returns true or false if any of them is missing.
*/
public function exists(): bool
{
return filesystem()->directory($this->path)->exists();
}
/**
* Gets size of a given directory in bytes.
*
* @return int Returns the size of the directory in bytes.
*/
public function size(): int
{
return filesystem()->directory($this->path)->size();
}
/**
* Determine if the given path is a directory.
*
* @return bool Returns TRUE if the given path exists and is a directory, FALSE otherwise.
*/
public function isDirectory(): bool
{
return filesystem()->directory($this->path)->isDirectory();
}
/**
* Return current path.
*
* @return string|null Current path
*/
public function path(): ?string
{
return filesystem()->directory($this->path)->path();
}
}

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class I18nExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('tr', fn(string $translate, array $values = [], string $locale = null) => '__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)),
new ExpressionFunction('__', fn(string $translate, array $values = [], string $locale = null) => '__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class ParsersExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('parsers', fn() => 'parsers()', fn($arguments) => parsers())
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class RegistryExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('registry', fn() => 'registry()', fn($arguments) => registry())
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class SerializersExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('serializers', fn() => 'serializers()', fn($arguments) => serializers())
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class SlugifyExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('slugify', fn() => 'slugify()', fn($arguments) => slugify())
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Entries\Expressions;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class StringsExpression implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
new ExpressionFunction('strings', fn($str) => 'strings($str)', fn($arguments, $str) => strings($str))
];
}
}

View File

@@ -76,6 +76,40 @@ entries:
directory: '/entries'
vars:
debug: false
expressions:
actions:
enabled: true
class: "Flextype\\Entries\\Expressions\\ActionsExpression"
registry:
enabled: true
class: "Flextype\\Entries\\Expressions\\RegistryExpression"
entries:
enabled: true
class: "Flextype\\Entries\\Expressions\\EntriesExpression"
filesystem:
enabled: true
class: "Flextype\\Entries\\Expressions\\FilesystemExpression"
i18n:
enabled: true
class: "Flextype\\Entries\\Expressions\\I18nExpression"
serializers:
enabled: true
class: "Flextype\\Entries\\Expressions\\SerializersExpression"
parsers:
enabled: true
class: "Flextype\\Entries\\Expressions\\ParsersExpression"
slugify:
enabled: true
class: "Flextype\\Entries\\Expressions\\SlugifyExpression"
strings:
enabled: true
class: "Flextype\\Entries\\Expressions\\StringsExpression"
collection:
enabled: true
class: "Flextype\\Entries\\Expressions\\CollectionExpression"
csrf:
enabled: true
class: "Flextype\\Entries\\Expressions\\CsrfExpression"
directives:
expressions:
enabled: true

View File

@@ -72,6 +72,40 @@ entries:
directory: '/entries'
vars:
debug: false
expressions:
actions:
enabled: true
class: "Flextype\\Entries\\Expressions\\ActionsExpression"
registry:
enabled: true
class: "Flextype\\Entries\\Expressions\\RegistryExpression"
entries:
enabled: true
class: "Flextype\\Entries\\Expressions\\EntriesExpression"
filesystem:
enabled: true
class: "Flextype\\Entries\\Expressions\\FilesystemExpression"
i18n:
enabled: true
class: "Flextype\\Entries\\Expressions\\I18nExpression"
serializers:
enabled: true
class: "Flextype\\Entries\\Expressions\\SerializersExpression"
parsers:
enabled: true
class: "Flextype\\Entries\\Expressions\\ParsersExpression"
slugify:
enabled: true
class: "Flextype\\Entries\\Expressions\\SlugifyExpression"
strings:
enabled: true
class: "Flextype\\Entries\\Expressions\\StringsExpression"
collection:
enabled: true
class: "Flextype\\Entries\\Expressions\\CollectionExpression"
csrf:
enabled: true
class: "Flextype\\Entries\\Expressions\\CsrfExpression"
directives:
expressions:
enabled: true

View File

@@ -12,7 +12,7 @@ afterEach(function () {
});
test('entry construct', function () {
expect(new Entries(registry()->get('flextype.settings.entries')))->toBeInstanceOf(Entries::class);
//expect(new Entries(registry()->get('flextype.settings.entries')))->toBeInstanceOf(Entries::class);
});
test('create new entry', function () {

View File

@@ -0,0 +1,17 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('actions expression', function () {
actions()->set('foo', 'Foo');
entries()->create('actions', ['test' => '[[ actions().get("foo") ]]']);
expect(entries()->fetch('actions')['test'])->toBe('Foo');
});

View File

@@ -0,0 +1,25 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('collection expression', function () {
entries()->create('collection', ['test-1' => '[[ collection({"foo": "Foo"}).get("foo") ]]',
'test-2' => '[[ collectionFromString("a,b", ",").offsetGet(0) ]]',
'test-3' => '[[ collectionFromJson("{\"foo\": \"Foo\"}").get("foo") ]]',
'test-4' => '[[ collectionFromQueryString("foo=Foo").get("foo") ]]',
'test-5' => '[[ collectionWithRange(0,10,1).offsetGet(10) ]]']);
expect(entries('collection')->fetch('collection')['test-1'])->toBe('Foo');
expect(entries('collection')->fetch('collection')['test-2'])->toBe('a');
expect(entries('collection')->fetch('collection')['test-3'])->toBe('Foo');
expect(entries('collection')->fetch('collection')['test-4'])->toBe('Foo');
expect(entries('collection')->fetch('collection')['test-5'])->toBe('10');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('strings expression', function () {
entries()->create('csrf', ['test' => '[[ csrf() ]]']);
expect(strings(entries()->fetch('csrf')['test'])->length())->toBe(178);
});

View File

@@ -0,0 +1,17 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('entries expression', function () {
entries()->create('foo', ['title' => 'Foo']);
entries()->create('entries', ['test' => '[[ entries().fetch("foo").get("title") ]]']);
expect(entries()->fetch('entries')['test'])->toBe('Foo');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('filesystem expression', function () {
entries()->create('filesystem', ['test' => '[[ filesystem().file("1.txt").extension() ]]']);
expect(entries()->fetch('filesystem')['test'])->toBe('txt');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('i18n expression', function () {
entries()->create('i18n', ['test' => '[[ __("foo") ~ tr("bar") ]]']);
expect(entries()->fetch('i18n')['test'])->toBe('foobar');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('parsers expression', function () {
entries()->create('parsers', ['test' => '[[ parsers().markdown().parse("**foo**") ]]']);
expect(trim(entries()->fetch('parsers')['test']))->toBe('<p><strong>foo</strong></p>');
});

View File

@@ -0,0 +1,17 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('registry expression', function () {
registry()->set('foo', 'Foo');
entries()->create('registry', ['test' => '[[ registry().get("foo") ]]']);
expect(entries()->fetch('registry')['test'])->toBe('Foo');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('serializers expression', function () {
entries()->create('serializers', ['test' => '[[ collection(serializers().json().decode("{\"foo\": \"Foo\"}")).get("foo") ]]']);
expect(trim(entries()->fetch('serializers')['test']))->toBe('Foo');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('slugify expression', function () {
entries()->create('slugify', ['test' => '[[ slugify().slugify("foo bar") ]]']);
expect(entries()->fetch('slugify')['test'])->toBe('foo-bar');
});

View File

@@ -0,0 +1,16 @@
<?php
use Flextype\Component\Filesystem\Filesystem;
beforeEach(function() {
filesystem()->directory(PATH['project'] . '/entries')->create();
});
afterEach(function (): void {
filesystem()->directory(PATH['project'] . '/entries')->delete();
});
test('strings expression', function () {
entries()->create('strings', ['test' => '[[ strings("Foo").lower() ]]']);
expect(entries()->fetch('strings')['test'])->toBe('foo');
});