forked from ashleyhood/php-lxd
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStr.php
More file actions
38 lines (31 loc) · 805 Bytes
/
Str.php
File metadata and controls
38 lines (31 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Opensaucesystems\Lxd\Helpers;
/**
* Inspired by Laravel
* https://github.com/illuminate/support/blob/master/Str.php
*/
class Str
{
/**
* The cache of studly-cased words.
*
* @var array
*/
protected static $studlyCache = [];
/**
* Convert a value to studly caps case.
*
* @param string $value
* @return string
*/
public static function studly($value)
{
$key = $value;
if (isset(static::$studlyCache[$key])) {
return static::$studlyCache[$key];
}
$words = explode(' ', str_replace(['-', '_'], ' ', $value));
$studlyWords = array_map(function ($word) { return ucfirst($word); }, $words);
return static::$studlyCache[$key] = implode($studlyWords);
}
}