1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 22:26:46 +02:00

feat(shortcodes): [strings] shortcode - add endsWith modifier

This commit is contained in:
Awilum
2022-05-05 09:17:27 +03:00
parent 09d9740b58
commit ac28422051
2 changed files with 7 additions and 0 deletions

View File

@@ -137,6 +137,10 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa
if ($key == 'countSubString') {
$content = (string) strings($content)->{'countSubString'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true);
}
if ($key == 'endsWith') {
$content = strings($content)->{'endsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? "true" : "false";
}
}
return (string) $content;

View File

@@ -88,4 +88,7 @@ test('[strings] shortcode', function () {
// crc32
$this->assertEquals(3632233996, parsers()->shortcodes()->parse('[strings crc32]test[/strings]'));
// endsWith
$this->assertEquals("true", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21/[/strings]'));
$this->assertEquals("false", parsers()->shortcodes()->parse('[strings endsWith="/"]/movies/sg-1/season-5/episode-21[/strings]'));
});