From 299c0f38481e30e252b67eae1cc21c445555cff3 Mon Sep 17 00:00:00 2001 From: Michael Krohn Date: Tue, 13 Feb 2024 18:43:18 +0100 Subject: [PATCH] feat: add a view helper to check what the string starts with --- .../Condition/String/StartWithViewHelper.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Classes/ViewHelpers/Condition/String/StartWithViewHelper.php diff --git a/Classes/ViewHelpers/Condition/String/StartWithViewHelper.php b/Classes/ViewHelpers/Condition/String/StartWithViewHelper.php new file mode 100644 index 0000000..e855f1f --- /dev/null +++ b/Classes/ViewHelpers/Condition/String/StartWithViewHelper.php @@ -0,0 +1,30 @@ +registerArgument('haystack', 'string', 'The string to search in.', true); + $this->registerArgument('needle', 'string', 'The substring to search for in the haystack.', true); + } + + /** + * @param array $arguments + */ + protected static function evaluateCondition($arguments = null) { + $haystack = strval($arguments['haystack'] ?? ''); + $needle = strval($arguments['needle'] ?? ''); + + return substr($haystack, 0, strlen($needle)) === $needle; + } +}