1
0
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:
Awilum
2022-07-11 13:45:10 +03:00
parent fbc61dbbe9
commit 076e22a415
2 changed files with 49 additions and 0 deletions

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;
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))];
}
}

View File

@@ -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);
});