From 6775292e189370a2e6f08e31591f7a79b65f4ff6 Mon Sep 17 00:00:00 2001 From: James Kingsley Date: Fri, 13 Nov 2020 16:48:19 +0000 Subject: [PATCH 1/2] Add classBasename() method to Stringable --- src/Illuminate/Support/Stringable.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php index 6c99cdb07142..a65d9f48beda 100644 --- a/src/Illuminate/Support/Stringable.php +++ b/src/Illuminate/Support/Stringable.php @@ -82,6 +82,16 @@ public function basename($suffix = '') { return new static(basename($this->value, $suffix)); } + + /** + * Get the basename of the class path. + * + * @return static + */ + public function classBasename() + { + return new static(class_basename($this->value)); + } /** * Get the portion of a string before the first occurrence of a given value. From e10900b4ab37f2fce0a5f7d3307ba2163a91346b Mon Sep 17 00:00:00 2001 From: James Kingsley Date: Fri, 13 Nov 2020 16:50:42 +0000 Subject: [PATCH 2/2] Add test --- tests/Support/SupportStringableTest.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php index 96c60ce558cc..652c0442a038 100644 --- a/tests/Support/SupportStringableTest.php +++ b/tests/Support/SupportStringableTest.php @@ -16,6 +16,14 @@ protected function stringable($string = '') { return new Stringable($string); } + + public function testClassBasename() + { + $this->assertEquals( + class_basename(static::class), + $this->stringable(static::class)->classBasename() + ); + } public function testIsAscii() {