From b8eec63128b4e8acdfd7f43030209a8441c47d8f Mon Sep 17 00:00:00 2001 From: Caleb Porzio Date: Thu, 23 Feb 2017 21:27:38 -0500 Subject: [PATCH] Add kebab case to Str with kebab_case helper (#18084) --- src/Illuminate/Support/Str.php | 11 +++++++++++ src/Illuminate/Support/helpers.php | 13 +++++++++++++ tests/Support/SupportStrTest.php | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 0ad5723cdc1d..41a8d6026d98 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -132,6 +132,17 @@ public static function is($pattern, $value) return (bool) preg_match('#^'.$pattern.'\z#u', $value); } + /** + * Convert a string to kebab case. + * + * @param string $value + * @return string + */ + public static function kebab($value) + { + return static::snake($value, '-'); + } + /** * Return the length of the given string. * diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 4eddc49cf30e..ae1980024449 100755 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -560,6 +560,19 @@ function head($array) } } +if (! function_exists('kebab_case')) { + /** + * Convert a string to kebab case. + * + * @param string $value + * @return string + */ + function kebab_case($value) + { + return Str::kebab($value); + } +} + if (! function_exists('last')) { /** * Get the last element from an array. diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php index 90945796b06d..b50259021099 100755 --- a/tests/Support/SupportStrTest.php +++ b/tests/Support/SupportStrTest.php @@ -123,6 +123,11 @@ public function testIs() $this->assertTrue(Str::is($patternObject, $valueObject)); } + public function testKebab() + { + $this->assertEquals('laravel-php-framework', Str::kebab('LaravelPhpFramework')); + } + public function testLower() { $this->assertEquals('foo bar baz', Str::lower('FOO BAR BAZ'));