mirror of
https://github.com/flextype/flextype.git
synced 2025-08-06 05:07:41 +02:00
feat(expressions): add date
expression function
This commit is contained in:
30
src/flextype/core/Entries/Expressions/DateExpression.php
Normal file
30
src/flextype/core/Entries/Expressions/DateExpression.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;
|
||||
|
||||
use function Flextype\registry;
|
||||
|
||||
class DateExpression implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [new ExpressionFunction('date', static fn (string $format, ?int $timestamp = null): string => '\date($format, $timestamp)', static fn (array $arguments, string $format, ?int $timestamp = null): string => \date($format, $timestamp))];
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
use function Glowy\Filesystem\filesystem;
|
||||
use function Flextype\entries;
|
||||
|
||||
beforeEach(function() {
|
||||
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->create();
|
||||
});
|
||||
|
||||
afterEach(function (): void {
|
||||
filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/entries')->delete();
|
||||
});
|
||||
|
||||
test('date expression', function () {
|
||||
$date = date("F j, Y, g:i a");
|
||||
entries()->create('date', ['test' => '[[ date("F j, Y, g:i a") ]]']);
|
||||
expect(entries()->fetch('date')['test'])->toBe($date);
|
||||
});
|
Reference in New Issue
Block a user