From 94c8a49ed1c6c90aef37d60da86235d65dbe262d Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 8 Nov 2024 14:28:56 +0100 Subject: [PATCH 1/6] Added a new expression to slugify a string --- src/Slugify.php | 55 ++++++++++++++++++++++++ src/StringExpressionLanguageProvider.php | 1 + 2 files changed, 56 insertions(+) create mode 100644 src/Slugify.php diff --git a/src/Slugify.php b/src/Slugify.php new file mode 100644 index 0000000..d1653c8 --- /dev/null +++ b/src/Slugify.php @@ -0,0 +1,55 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $value, string $divider = '-'): string + { + return << Date: Fri, 8 Nov 2024 14:29:29 +0100 Subject: [PATCH 2/6] Ran php-cs-fixer --- src/AsString.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; } From cf8e2fbf03f94a3f2f42c39dd28ee81fe3122378 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 8 Nov 2024 13:30:04 +0000 Subject: [PATCH 3/6] [rector] Rector fixes --- src/Slugify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Slugify.php b/src/Slugify.php index d1653c8..21155e8 100644 --- a/src/Slugify.php +++ b/src/Slugify.php @@ -41,7 +41,7 @@ private function evaluate(array $context, string $value, string $divider = '-'): { $text = preg_replace('~[^\pL\d]+~u', $divider, $value); $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); - $text = preg_replace('~[^-\w]+~', '', $text); + $text = preg_replace('~[^\-\w]+~', '', $text); $text = trim($text, $divider); $text = preg_replace('~-+~', $divider, $text); $text = strtolower($text); From 26ff33a8b01ba8af1c02b3c1ddcd5936eb12f2a8 Mon Sep 17 00:00:00 2001 From: sebprt Date: Fri, 8 Nov 2024 15:32:25 +0100 Subject: [PATCH 4/6] Create a new expression to get file extension --- src/FileExtension.php | 37 ++++++++++++++++++++++++ src/StringExpressionLanguageProvider.php | 1 + 2 files changed, 38 insertions(+) create mode 100644 src/FileExtension.php diff --git a/src/FileExtension.php b/src/FileExtension.php new file mode 100644 index 0000000..c10187e --- /dev/null +++ b/src/FileExtension.php @@ -0,0 +1,37 @@ +compile(...)->bindTo($this), + $this->evaluate(...)->bindTo($this) + ); + } + + private function compile(string $value): string + { + return << Date: Fri, 8 Nov 2024 15:38:45 +0100 Subject: [PATCH 5/6] Ran php-cs-fixer --- src/DateTime.php | 2 +- src/FileExtension.php | 10 +++------- src/Now.php | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) 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 index c10187e..188fa7a 100644 --- a/src/FileExtension.php +++ b/src/FileExtension.php @@ -21,17 +21,13 @@ private function compile(string $value): string { return << Date: Fri, 8 Nov 2024 15:55:44 +0100 Subject: [PATCH 6/6] Improve the fileExtension expression --- src/FileExtension.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/FileExtension.php b/src/FileExtension.php index 188fa7a..bc89121 100644 --- a/src/FileExtension.php +++ b/src/FileExtension.php @@ -20,14 +20,29 @@ public function __construct($name) private function compile(string $value): string { return <<