Class Inflector
Pluralize and singularize English words.
Inflector pluralizes and singularizes English nouns. Used by CakePHP's naming conventions throughout the framework.
Properties summary
- $_cache protected static
arrayMethod cache array.
- $_initialState protected static
arrayThe initial state of Inflector so reset() works.
- $_irregular protected static
arrayIrregular rules
- $_plural protected static
arrayPlural inflector rules
- $_singular protected static
arraySingular inflector rules
- $_uninflected protected static
arrayWords that should not be inflected
Method Summary
- classify() public static
Returns Cake model class name ("Person" for the database table "people".) for given database table.
- humanize() public static
Returns the input lower_case_delimited_string as 'A Human Readable String'.
- reset() public static
Clears Inflectors inflected value caches. And resets the inflection rules to the initial values.
- rules() public static
Adds custom inflection $rules, of either 'plural', 'singular', 'uninflected' or 'irregular' $type.
- tableize() public static
Returns corresponding table name for given model $className. ("people" for the model class "Person").
Method Detail
_cache() protected static
_cache(string $type, string $key, mixed $value)
Cache inflected values, and return if already available
Parameters
-
string$type Inflection type
-
string$key Original value
-
string|false$value optional Inflected value
Returns
string|falseInflected value on cache hit or false on cache miss.
camelize() public static
camelize(string $string, string $delimiter)
Returns the input lower_case_delimited_string as a CamelCasedString.
Parameters
-
string$string String to camelize
-
string$delimiter optional the delimiter in the input string
Returns
stringCamelizedStringLikeThis.
Links
classify() public static
classify(string $tableName)
Returns Cake model class name ("Person" for the database table "people".) for given database table.
Parameters
-
string$tableName Name of database table to get class name for
Returns
stringClass name
Links
dasherize() public static
dasherize(string $string)
Returns the input CamelCasedString as an dashed-string.
Also replaces underscores with dashes
Parameters
-
string$string The string to dasherize.
Returns
stringDashed version of the input string
delimit() public static
delimit(string $string, string $delimiter)
Expects a CamelCasedInputString, and produces a lower_case_delimited_string
Parameters
-
string$string String to delimit
-
string$delimiter optional the character to use as a delimiter
Returns
stringdelimited string
humanize() public static
humanize(string $string, string $delimiter)
Returns the input lower_case_delimited_string as 'A Human Readable String'.
(Underscores are replaced by spaces and capitalized following words.)
Parameters
-
string$string String to be humanized
-
string$delimiter optional the character to replace with a space
Returns
stringHuman-readable string
Links
pluralize() public static
pluralize(string $word)
Return $word in plural form.
Parameters
-
string$word Word in singular
Returns
stringWord in plural
Links
reset() public static
reset()
Clears Inflectors inflected value caches. And resets the inflection rules to the initial values.
rules() public static
rules(string $type, array $rules, bool $reset)
Adds custom inflection $rules, of either 'plural', 'singular', 'uninflected' or 'irregular' $type.
Usage:
Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']);
Inflector::rules('irregular', ['red' => 'redlings']);
Inflector::rules('uninflected', ['dontinflectme']); Parameters
-
string$type The type of inflection, either 'plural', 'singular', or 'uninflected'.
-
array$rules Array of rules to be added.
-
bool$reset optional If true, will unset default inflections for all new rules that are being defined in $rules.
singularize() public static
singularize(string $word)
Return $word in singular form.
Parameters
-
string$word Word in plural
Returns
stringWord in singular
Links
tableize() public static
tableize(string $className)
Returns corresponding table name for given model $className. ("people" for the model class "Person").
Parameters
-
string$className Name of class to get database table name for
Returns
stringName of the database table for given class
Links
underscore() public static
underscore(string $string)
Returns the input CamelCasedString as an underscored_string.
Also replaces dashes with underscores
Parameters
-
string$string CamelCasedString to be "underscorized"
Returns
stringunderscore_version of the input string
Links
variable() public static
variable(string $string)
Returns camelBacked version of an underscored string.
Parameters
-
string$string String to convert.
Returns
stringin variable form
Links
Property Detail
$_cache protected static
Method cache array.
Type
array$_initialState protected static
The initial state of Inflector so reset() works.
Type
array$_irregular protected static
Irregular rules
Type
array$_plural protected static
Plural inflector rules
Type
array$_singular protected static
Singular inflector rules
Type
array$_uninflected protected static
Words that should not be inflected
Type
array
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.0/class-Cake.Utility.Inflector.html