File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Expand file tree Collapse file tree 2 files changed +32
-2
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+ final class AsString extends ExpressionFunction
10+ {
11+ public function __construct ($ name )
12+ {
13+ parent ::__construct (
14+ $ name ,
15+ $ this ->compile (...)->bindTo ($ this ),
16+ $ this ->evaluate (...)->bindTo ($ this )
17+ );
18+ }
19+
20+ private function compile (string $ value ): string
21+ {
22+ return <<<PHP
23+ ((string) {$ value })
24+ PHP ;
25+ }
26+
27+ private function evaluate (array $ context , int |float |string $ value ): string
28+ {
29+ return (string ) $ value ;
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -27,8 +27,6 @@ public function getFunctions(): array
2727 ExpressionFunction::fromPhp ('ucwords ' , 'capitalizeWords ' ),
2828 ExpressionFunction::fromPhp ('rtrim ' , 'removeWhitespaces ' ),
2929 ExpressionFunction::fromPhp ('explode ' , 'splitIntoArray ' ),
30- ExpressionFunction::fromPhp ('strval ' , 'transformToString ' ),
31- ExpressionFunction::fromPhp ('strrchr ' , 'findLast ' ),
3230 new FileName ('fileName ' ),
3331 new DateTime ('dateTime ' ),
3432 new FormatDate ('formatDate ' ),
@@ -37,6 +35,7 @@ public function getFunctions(): array
3735 new ConvertCharCode ('convertCharCode ' ),
3836 new AsFloat ('asFloat ' ),
3937 new AsInteger ('asInteger ' ),
38+ new AsString ('asString ' ),
4039 ];
4140 }
4241}
You can’t perform that action at this time.
0 commit comments