Skip to content

Commit

Permalink
Add kebab case to Str with kebab_case helper (#18084)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio authored and taylorotwell committed Feb 24, 2017
1 parent e4c0de6 commit b8eec63
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tests/Support/SupportStrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit b8eec63

Please sign in to comment.