diff --git a/src/AsString.php b/src/AsString.php index 16d1890..9c20b6a 100644 --- a/src/AsString.php +++ b/src/AsString.php @@ -24,7 +24,7 @@ private function compile(string $value): string PHP; } - private function evaluate(array $context, int|float|string $value): string + private function evaluate(array $context, float|int|string $value): string { return (string) $value; } diff --git a/src/DateTime.php b/src/DateTime.php index bf0f94a..c35d449 100644 --- a/src/DateTime.php +++ b/src/DateTime.php @@ -24,7 +24,7 @@ private function compile(string $date, string $format, string $timezone = 'null' PHP; } - private function evaluate(array $context, string $date, string $format, string $timezone = null) + private function evaluate(array $context, string $date, string $format, ?string $timezone = null) { return \DateTimeImmutable::createFromFormat($format, $date, null !== $timezone ? new \DateTimeZone($timezone) : null); } diff --git a/src/FileExtension.php b/src/FileExtension.php new file mode 100644 index 0000000..bc89121 --- /dev/null +++ b/src/FileExtension.php @@ -0,0 +1,48 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $value): string + { + return <<compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $value, string $divider = '-'): string + { + return <<