File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Kiboko \Component \StringExpressionLanguage ;
6+
7+ use Symfony \Component \ExpressionLanguage \ExpressionFunction ;
8+
9+ class Now extends ExpressionFunction
10+ {
11+ public function __construct ($ name )
12+ {
13+ parent ::__construct (
14+ $ name ,
15+ \Closure::fromCallable ([$ this , 'compile ' ])->bindTo ($ this ),
16+ \Closure::fromCallable ([$ this , 'evaluate ' ])->bindTo ($ this )
17+ );
18+ }
19+
20+ private function compile (string $ timezone = null )
21+ {
22+ return <<<PHP
23+ (new \DateTime('now', {$ timezone } !== null ? new \DateTimeZone( {$ timezone }) : null))
24+ PHP ;
25+ }
26+
27+ private function evaluate (array $ context , string $ timezone = null )
28+ {
29+ return new \DateTime ('now ' , $ timezone !== null ? new \DateTimeZone ($ timezone ) : null );
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -16,10 +16,12 @@ public function getFunctions(): array
1616 ExpressionFunction::fromPhp ('strtolower ' , 'toLowerCase ' ),
1717 ExpressionFunction::fromPhp ('substr ' , 'search ' ),
1818 ExpressionFunction::fromPhp ('strtoupper ' , 'toUpperCase ' ),
19+ ExpressionFunction::fromPhp ('number_format ' , 'formatNumber ' ),
1920 new FileName ('fileName ' ),
2021 new DateTime ('dateTime ' ),
2122 new FormatDate ('formatDate ' ),
2223 new TruncateFileName ('truncateFileName ' ),
24+ new Now ('now ' ),
2325 ];
2426 }
2527}
You can’t perform that action at this time.
0 commit comments