mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 13:16:45 +02:00
feat(expressions): add const
expression
This commit is contained in:
30
src/flextype/core/Entries/Expressions/ConstExpression.php
Normal file
30
src/flextype/core/Entries/Expressions/ConstExpression.php
Normal 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 ConstExpression implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new ExpressionFunction('const', fn(string $const) => "defined($const) ? constant($const) : ''", fn($arguments, string $const) => defined($const) ? constant($const) : '')
|
||||
];
|
||||
}
|
||||
}
|
@@ -116,6 +116,9 @@ entries:
|
||||
field:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\FieldExpression"
|
||||
const:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\ConstExpression"
|
||||
directives:
|
||||
expressions:
|
||||
enabled: true
|
||||
|
3
tests/fixtures/settings/settings.yaml
vendored
3
tests/fixtures/settings/settings.yaml
vendored
@@ -112,6 +112,9 @@ entries:
|
||||
field:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\FieldExpression"
|
||||
const:
|
||||
enabled: true
|
||||
class: "Flextype\\Entries\\Expressions\\ConstExpression"
|
||||
directives:
|
||||
expressions:
|
||||
enabled: true
|
||||
|
@@ -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('const expression', function () {
|
||||
define('test-expression-const', 'Foo');
|
||||
entries()->create('const', ['test' => '[[ const("test-expression-const") ]]']);
|
||||
expect(entries()->fetch('const')['test'])->toBe('Foo');
|
||||
});
|
Reference in New Issue
Block a user