1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ICanBoogie package. |
5
|
|
|
* |
6
|
|
|
* (c) Olivier Laviale <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ICanBoogie; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default inflector locale. |
16
|
|
|
*/ |
17
|
|
|
const INFLECTOR_DEFAULT_LOCALE = 'en'; |
18
|
|
|
|
19
|
|
|
if (!function_exists(__NAMESPACE__ . '\downcase')) |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Returns an lowercase string. |
23
|
|
|
* |
24
|
|
|
* @param string $str |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
function downcase($str) |
29
|
|
|
{ |
30
|
|
|
return mb_strtolower($str); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (!function_exists(__NAMESPACE__ . '\upcase')) |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Returns an uppercase string. |
38
|
|
|
* |
39
|
|
|
* @param string $str |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
function upcase($str) |
44
|
|
|
{ |
45
|
|
|
return mb_strtoupper($str); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if (!function_exists(__NAMESPACE__ . '\capitalize')) |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* Returns a copy of str with the first character converted to uppercase and the |
53
|
|
|
* remainder to lowercase. |
54
|
|
|
* |
55
|
|
|
* @param string $str |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
function capitalize($str) |
60
|
|
|
{ |
61
|
|
|
return upcase(mb_substr($str, 0, 1)) . downcase(mb_substr($str, 1)); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Forwards calls to `Inflector::get()->pluralize()`. |
67
|
|
|
* |
68
|
|
|
* @param string $word |
69
|
|
|
* @param string $locale Locale identifier. |
70
|
|
|
* |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
function pluralize($word, $locale = INFLECTOR_DEFAULT_LOCALE) |
74
|
|
|
{ |
75
|
|
|
return Inflector::get($locale)->pluralize($word); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Forwards calls to `Inflector::get()->singularize()`. |
80
|
|
|
* |
81
|
|
|
* @param string $word |
82
|
|
|
* @param string $locale Locale identifier. |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
function singularize($word, $locale = INFLECTOR_DEFAULT_LOCALE) |
87
|
|
|
{ |
88
|
|
|
return Inflector::get($locale)->singularize($word); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Forwards calls to `Inflector::get()->camelize()`. |
93
|
|
|
* |
94
|
|
|
* @param string $str |
95
|
|
|
* @param bool $uppercase_first_letter |
96
|
|
|
* @param string $locale Locale identifier. |
97
|
|
|
* |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
function camelize($str, $uppercase_first_letter = false, $locale = INFLECTOR_DEFAULT_LOCALE) |
101
|
|
|
{ |
102
|
|
|
return Inflector::get($locale)->camelize($str, $uppercase_first_letter); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Forwards calls to `Inflector::get()->underscore()`. |
107
|
|
|
* |
108
|
|
|
* @param string $camel_cased_word |
109
|
|
|
* @param string $locale Locale identifier. |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
function underscore($camel_cased_word, $locale = INFLECTOR_DEFAULT_LOCALE) |
114
|
|
|
{ |
115
|
|
|
return Inflector::get($locale)->underscore($camel_cased_word); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Forwards calls to `Inflector::get()->hyphenate()`. |
120
|
|
|
* |
121
|
|
|
* @param string $str |
122
|
|
|
* @param string $locale Locale identifier. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
function hyphenate($str, $locale = INFLECTOR_DEFAULT_LOCALE) |
127
|
|
|
{ |
128
|
|
|
return Inflector::get($locale)->hyphenate($str); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Forwards calls to `Inflector::get()->humanize()`. |
133
|
|
|
* |
134
|
|
|
* @param string $lower_case_and_underscored_word |
135
|
|
|
* @param string $locale Locale identifier. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
|
|
function humanize($lower_case_and_underscored_word, $locale = INFLECTOR_DEFAULT_LOCALE) |
140
|
|
|
{ |
141
|
|
|
return Inflector::get($locale)->humanize($lower_case_and_underscored_word); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Forwards calls to `Inflector::get()->titleize()`. |
146
|
|
|
* |
147
|
|
|
* @param string $str |
148
|
|
|
* @param string $locale Locale identifier. |
149
|
|
|
* |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
function titleize($str, $locale = INFLECTOR_DEFAULT_LOCALE) |
153
|
|
|
{ |
154
|
|
|
return Inflector::get($locale)->titleize($str); |
155
|
|
|
} |
156
|
|
|
|