From 89aff9aedba592fd59adbd9f9778ce260050cf50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20V=C3=A1radi?= Date: Mon, 29 Nov 2021 16:22:35 +0100 Subject: [PATCH 1/2] Add Str::reverse --- src/Illuminate/Support/Str.php | 11 +++++++++++ tests/Support/SupportStrTest.php | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index e476174193cc..5799c63f097f 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -675,6 +675,17 @@ public static function remove($search, $subject, $caseSensitive = true) return $subject; } + /** + * Reverse the given string. + * + * @param string $value + * @return string + */ + public static function reverse(string $value) + { + return implode(array_reverse(mb_str_split($value))); + } + /** * Begin a string with a single instance of a given value. * diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 5aaa07638ac0..bbdebd907637 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -418,6 +418,13 @@ public function testRemove() $this->assertSame('Foobar', Str::remove(['f', '|'], 'Foo|bar')); } + public function testReverse() + { + $this->assertSame('FooBar', Str::reverse('raBooF')); + $this->assertSame('Teniszütő', Str::reverse('őtüzsineT')); + $this->assertSame('❤MultiByte☆', Str::reverse('☆etyBitluM❤')); + } + public function testSnake() { $this->assertSame('laravel_p_h_p_framework', Str::snake('LaravelPHPFramework')); From 881300f5d9c7ba73d6f86997e40606334b7a97db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20V=C3=A1radi?= Date: Mon, 29 Nov 2021 16:23:26 +0100 Subject: [PATCH 2/2] Add Stringable::reverse --- src/Illuminate/Support/Stringable.php | 10 ++++++++++ tests/Support/SupportStringableTest.php | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index a7d21b0ed236..1927112c60b2 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -492,6 +492,16 @@ public function remove($search, $caseSensitive = true) return new static(Str::remove($search, $this->value, $caseSensitive)); } + /** + * Reverse the string. + * + * @return static + */ + public function reverse() + { + return new static(Str::reverse($this->value)); + } + /** * Repeat the string. * diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 01d9670108ea..8377b6f85453 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -538,6 +538,13 @@ public function testRemove() $this->assertSame('Foobar', (string) $this->stringable('Foo|bar')->remove(['f', '|'])); } + public function testReverse() + { + $this->assertSame('FooBar', (string) $this->stringable('raBooF')->reverse()); + $this->assertSame('Teniszütő', (string) $this->stringable('őtüzsineT')->reverse()); + $this->assertSame('❤MultiByte☆', (string) $this->stringable('☆etyBitluM❤')->reverse()); + } + public function testSnake() { $this->assertSame('laravel_p_h_p_framework', (string) $this->stringable('LaravelPHPFramework')->snake());