1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\Common\Inflector; |
21
|
|
|
|
22
|
|
|
use BadMethodCallException; |
23
|
|
|
use Doctrine\Inflector\Inflector as InflectorObject; |
24
|
|
|
use Doctrine\Inflector\InflectorFactory; |
25
|
|
|
use Doctrine\Inflector\Language; |
26
|
|
|
use function sprintf; |
27
|
|
|
use function trigger_error; |
28
|
|
|
use const E_USER_DEPRECATED; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @deprecated |
32
|
|
|
*/ |
33
|
|
|
final class Inflector |
34
|
|
|
{ |
35
|
|
|
/** @var InflectorObject|null */ |
36
|
|
|
private static $instance; |
37
|
|
|
|
38
|
512 |
|
private static function getInstance() : InflectorObject |
39
|
|
|
{ |
40
|
512 |
|
if (self::$instance === null) { |
41
|
1 |
|
self::$instance = (new InflectorFactory())(Language::ENGLISH); |
42
|
|
|
} |
43
|
|
|
|
44
|
512 |
|
return self::$instance; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'. |
49
|
|
|
* |
50
|
|
|
* @deprecated |
51
|
|
|
*/ |
52
|
3 |
|
public static function tableize(string $word) : string |
53
|
|
|
{ |
54
|
3 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
55
|
|
|
|
56
|
3 |
|
return self::getInstance()->tableize($word); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'. |
61
|
|
|
*/ |
62
|
6 |
|
public static function classify(string $word) : string |
63
|
|
|
{ |
64
|
6 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
65
|
|
|
|
66
|
6 |
|
return self::getInstance()->classify($word); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Camelizes a word. This uses the classify() method and turns the first character to lowercase. |
71
|
|
|
* |
72
|
|
|
* @deprecated |
73
|
|
|
*/ |
74
|
5 |
|
public static function camelize(string $word) : string |
75
|
|
|
{ |
76
|
5 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
77
|
|
|
|
78
|
5 |
|
return self::getInstance()->camelize($word); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Uppercases words with configurable delimeters between words. |
83
|
|
|
* |
84
|
|
|
* Takes a string and capitalizes all of the words, like PHP's built-in |
85
|
|
|
* ucwords function. This extends that behavior, however, by allowing the |
86
|
|
|
* word delimeters to be configured, rather than only separating on |
87
|
|
|
* whitespace. |
88
|
|
|
* |
89
|
|
|
* Here is an example: |
90
|
|
|
* <code> |
91
|
|
|
* <?php |
92
|
|
|
* $string = 'top-o-the-morning to all_of_you!'; |
93
|
|
|
* echo \Doctrine\Common\Inflector\Inflector::ucwords($string); |
94
|
|
|
* // Top-O-The-Morning To All_of_you! |
95
|
|
|
* |
96
|
|
|
* echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ '); |
97
|
|
|
* // Top-O-The-Morning To All_Of_You! |
98
|
|
|
* ?> |
99
|
|
|
* </code> |
100
|
|
|
* |
101
|
|
|
* @param string $string The string to operate on. |
102
|
|
|
* @param string $delimiters A list of word separators. |
103
|
|
|
* |
104
|
|
|
* @return string The string with all delimeter-separated words capitalized. |
105
|
|
|
* |
106
|
|
|
* @deprecated |
107
|
|
|
*/ |
108
|
2 |
|
public static function ucwords(string $string, string $delimiters = " \n\t\r\0\x0B-") : string |
109
|
|
|
{ |
110
|
2 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please use the "ucwords" function instead.', __METHOD__), E_USER_DEPRECATED); |
111
|
|
|
|
112
|
2 |
|
return ucwords($string, $delimiters); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Clears Inflectors inflected value caches, and resets the inflection |
117
|
|
|
* rules to the initial values. |
118
|
|
|
* |
119
|
|
|
* @deprecated |
120
|
|
|
*/ |
121
|
|
|
public static function reset() : void |
122
|
|
|
{ |
123
|
|
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Adds custom inflection $rules, of either 'plural' or 'singular' $type. |
128
|
|
|
* |
129
|
|
|
* ### Usage: |
130
|
|
|
* |
131
|
|
|
* {{{ |
132
|
|
|
* Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables')); |
133
|
|
|
* Inflector::rules('plural', array( |
134
|
|
|
* 'rules' => array('/^(inflect)ors$/i' => '\1ables'), |
135
|
|
|
* 'uninflected' => array('dontinflectme'), |
136
|
|
|
* 'irregular' => array('red' => 'redlings') |
137
|
|
|
* )); |
138
|
|
|
* }}} |
139
|
|
|
* |
140
|
|
|
* @param string $type The type of inflection, either 'plural' or 'singular' |
141
|
|
|
* @param array|iterable $rules An array of rules to be added. |
142
|
|
|
* @param boolean $reset If true, will unset default inflections for all |
143
|
|
|
* new rules that are being defined in $rules. |
144
|
|
|
* |
145
|
|
|
* @return void |
146
|
|
|
* |
147
|
|
|
* @deprecated |
148
|
|
|
*/ |
149
|
|
|
public static function rules(string $type, iterable $rules, bool $reset = false) : void |
|
|
|
|
150
|
|
|
{ |
151
|
|
|
throw new BadMethodCallException('Adding custom rules is no longer supported in Doctrine Inflector 2.0.'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Returns a word in plural form. |
156
|
|
|
* |
157
|
|
|
* @param string $word The word in singular form. |
158
|
|
|
* |
159
|
|
|
* @return string The word in plural form. |
160
|
|
|
* |
161
|
|
|
* @deprecated |
162
|
|
|
*/ |
163
|
249 |
|
public static function pluralize(string $word) : string |
164
|
|
|
{ |
165
|
249 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
166
|
|
|
|
167
|
249 |
|
return self::getInstance()->pluralize($word); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Returns a word in singular form. |
172
|
|
|
* |
173
|
|
|
* @param string $word The word in plural form. |
174
|
|
|
* |
175
|
|
|
* @return string The word in singular form. |
176
|
|
|
* |
177
|
|
|
* @deprecated |
178
|
|
|
*/ |
179
|
249 |
|
public static function singularize(string $word) : string |
180
|
|
|
{ |
181
|
249 |
|
@trigger_error(sprintf('The "%s" method is deprecated and will be dropped in Doctrine Inflector 3.0. Please update to the new Inflector API.', __METHOD__), E_USER_DEPRECATED); |
182
|
|
|
|
183
|
249 |
|
return self::getInstance()->singularize($word); |
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.