Class Inflector
Pluralize and singularize English words.
Inflector pluralizes and singularizes English nouns. Used by CakePHP's naming conventions throughout the framework.
Link: https://book.cakephp.org/3.0/en/core-libraries/inflector.html
Location: Utility/Inflector.php
Properties summary
-
$_cache
protected staticarray
Method cache array. -
$_initialState
protected staticarray
The initial state of Inflector so reset() works. -
$_irregular
protected staticarray
Irregular rules -
$_plural
protected staticarray
Plural inflector rules -
$_singular
protected staticarray
Singular inflector rules -
$_transliteration
protected staticarray
Default map of accented and special characters to ASCII characters -
$_uninflected
protected staticarray
Words that should not be inflected
Method Summary
-
_cache() protected static
Cache inflected values, and return if already available -
camelize() public static
Returns the input lower_case_delimited_string as a CamelCasedString. -
classify() public static
Returns Cake model class name ("Person" for the database table "people".) for given database table. -
dasherize() public static
Returns the input CamelCasedString as an dashed-string. -
delimit() public static
Expects a CamelCasedInputString, and produces a lower_case_delimited_string -
humanize() public static
Returns the input lower_case_delimited_string as 'A Human Readable String'. (Underscores are replaced by spaces and capitalized following words.)
-
pluralize() public static
Return $word in plural form. -
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', 'irregular' or 'transliteration' $type.
-
singularize() public static
Return $word in singular form. -
slug() public static
Returns a string with all spaces converted to dashes (by default), accented characters converted to non-accented characters, and non word characters removed.
-
tableize() public static
Returns corresponding table name for given model $className. ("people" for the model class "Person"). -
underscore() public static
Returns the input CamelCasedString as an underscored_string. -
variable() public static
Returns camelBacked version of an underscored string.
Method Detail
_cache() protected static ¶
_cache( string $type , string $key , string|boolean $value false )
Cache inflected values, and return if already available
Parameters
- string $type
- Inflection type
- string $key
- Original value
- string|boolean $value optional false
- Inflected value
Returns
Inflected 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
CamelizedStringLikeThis.
Link
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
Class name
Link
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
Dashed 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
delimited 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
Human-readable string
Link
pluralize() public static ¶
pluralize( string $word )
Return $word in plural form.
Parameters
- string $word
- Word in singular
Returns
Word in plural
Link
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 , boolean $reset false )
Adds custom inflection $rules, of either 'plural', 'singular', 'uninflected', 'irregular' or 'transliteration' $type.
Usage:
Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); Inflector::rules('irregular', ['red' => 'redlings']); Inflector::rules('uninflected', ['dontinflectme']); Inflector::rules('transliteration', ['/å/' => 'aa']);
Parameters
- string $type
The type of inflection, either 'plural', 'singular', 'uninflected' or 'transliteration'.
- array $rules
- Array of rules to be added.
- boolean $reset optional false
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
Word in singular
Link
slug() public static ¶
slug( string $string , string $replacement '-' )
Returns a string with all spaces converted to dashes (by default), accented characters converted to non-accented characters, and non word characters removed.
Deprecated
Parameters
- string $string
- the string you want to slug
- string $replacement optional '-'
- will replace keys in map
Returns
Link
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
Name of the database table for given class
Link
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
underscore_version of the input string
Link
variable() public static ¶
variable( string $string )
Returns camelBacked version of an underscored string.
Parameters
- string $string
- String to convert.
Returns
in variable form
Link
Properties detail
$_irregular ¶
Irregular rules
[ 'atlas' => 'atlases', 'beef' => 'beefs', 'brief' => 'briefs', 'brother' => 'brothers', 'cafe' => 'cafes', 'child' => 'children', 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'criterion' => 'criteria', 'ganglion' => 'ganglions', 'genie' => 'genies', 'genus' => 'genera', 'graffito' => 'graffiti', 'hoof' => 'hoofs', 'loaf' => 'loaves', 'man' => 'men', 'money' => 'monies', 'mongoose' => 'mongooses', 'move' => 'moves', 'mythos' => 'mythoi', 'niche' => 'niches', 'numen' => 'numina', 'occiput' => 'occiputs', 'octopus' => 'octopuses', 'opus' => 'opuses', 'ox' => 'oxen', 'penis' => 'penises', 'person' => 'people', 'sex' => 'sexes', 'soliloquy' => 'soliloquies', 'testis' => 'testes', 'trilby' => 'trilbys', 'turf' => 'turfs', 'potato' => 'potatoes', 'hero' => 'heroes', 'tooth' => 'teeth', 'goose' => 'geese', 'foot' => 'feet', 'foe' => 'foes', 'sieve' => 'sieves', 'cache' => 'caches', ]
$_plural ¶
Plural inflector rules
[ '/(s)tatus$/i' => '\1tatuses', '/(quiz)$/i' => '\1zes', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice', '/(matr|vert|ind)(ix|ex)$/i' => '\1ices', '/(x|ch|ss|sh)$/i' => '\1es', '/([^aeiouy]|qu)y$/i' => '\1ies', '/(hive)$/i' => '\1s', '/(chef)$/i' => '\1s', '/(?:([^f])fe|([lre])f)$/i' => '\1\2ves', '/sis$/i' => 'ses', '/([ti])um$/i' => '\1a', '/(p)erson$/i' => '\1eople', '/(?<!u)(m)an$/i' => '\1en', '/(c)hild$/i' => '\1hildren', '/(buffal|tomat)o$/i' => '\1\2oes', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin)us$/i' => '\1i', '/us$/i' => 'uses', '/(alias)$/i' => '\1es', '/(ax|cris|test)is$/i' => '\1es', '/s$/' => 's', '/^$/' => '', '/$/' => 's', ]
$_singular ¶
Singular inflector rules
[ '/(s)tatuses$/i' => '\1\2tatus', '/^(.*)(menu)s$/i' => '\1\2', '/(quiz)zes$/i' => '\\1', '/(matr)ices$/i' => '\1ix', '/(vert|ind)ices$/i' => '\1ex', '/^(ox)en/i' => '\1', '/(alias)(es)*$/i' => '\1', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', '/([ftw]ax)es/i' => '\1', '/(cris|ax|test)es$/i' => '\1is', '/(shoe)s$/i' => '\1', '/(o)es$/i' => '\1', '/ouses$/' => 'ouse', '/([^a])uses$/' => '\1us', '/([m|l])ice$/i' => '\1ouse', '/(x|ch|ss|sh)es$/i' => '\1', '/(m)ovies$/i' => '\1\2ovie', '/(s)eries$/i' => '\1\2eries', '/([^aeiouy]|qu)ies$/i' => '\1y', '/(tive)s$/i' => '\1', '/(hive)s$/i' => '\1', '/(drive)s$/i' => '\1', '/([le])ves$/i' => '\1f', '/([^rfoa])ves$/i' => '\1fe', '/(^analy)ses$/i' => '\1sis', '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', '/([ti])a$/i' => '\1um', '/(p)eople$/i' => '\1\2erson', '/(m)en$/i' => '\1an', '/(c)hildren$/i' => '\1\2hild', '/(n)ews$/i' => '\1\2ews', '/eaus$/' => 'eau', '/^(.*us)$/' => '\\1', '/s$/i' => '' ]
$_transliteration ¶
Default map of accented and special characters to ASCII characters
[ 'ä' => 'ae', 'æ' => 'ae', 'ǽ' => 'ae', 'ö' => 'oe', 'œ' => 'oe', 'ü' => 'ue', 'Ä' => 'Ae', 'Ü' => 'Ue', 'Ö' => 'Oe', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Å' => 'A', 'Ǻ' => 'A', 'Ā' => 'A', 'Ă' => 'A', 'Ą' => 'A', 'Ǎ' => 'A', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'å' => 'a', 'ǻ' => 'a', 'ā' => 'a', 'ă' => 'a', 'ą' => 'a', 'ǎ' => 'a', 'ª' => 'a', 'Ç' => 'C', 'Ć' => 'C', 'Ĉ' => 'C', 'Ċ' => 'C', 'Č' => 'C', 'ç' => 'c', 'ć' => 'c', 'ĉ' => 'c', 'ċ' => 'c', 'č' => 'c', 'Ð' => 'D', 'Ď' => 'D', 'Đ' => 'D', 'ð' => 'd', 'ď' => 'd', 'đ' => 'd', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ē' => 'E', 'Ĕ' => 'E', 'Ė' => 'E', 'Ę' => 'E', 'Ě' => 'E', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ē' => 'e', 'ĕ' => 'e', 'ė' => 'e', 'ę' => 'e', 'ě' => 'e', 'Ĝ' => 'G', 'Ğ' => 'G', 'Ġ' => 'G', 'Ģ' => 'G', 'Ґ' => 'G', 'ĝ' => 'g', 'ğ' => 'g', 'ġ' => 'g', 'ģ' => 'g', 'ґ' => 'g', 'Ĥ' => 'H', 'Ħ' => 'H', 'ĥ' => 'h', 'ħ' => 'h', 'І' => 'I', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ї' => 'Yi', 'Ï' => 'I', 'Ĩ' => 'I', 'Ī' => 'I', 'Ĭ' => 'I', 'Ǐ' => 'I', 'Į' => 'I', 'İ' => 'I', 'і' => 'i', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ї' => 'yi', 'ĩ' => 'i', 'ī' => 'i', 'ĭ' => 'i', 'ǐ' => 'i', 'į' => 'i', 'ı' => 'i', 'Ĵ' => 'J', 'ĵ' => 'j', 'Ķ' => 'K', 'ķ' => 'k', 'Ĺ' => 'L', 'Ļ' => 'L', 'Ľ' => 'L', 'Ŀ' => 'L', 'Ł' => 'L', 'ĺ' => 'l', 'ļ' => 'l', 'ľ' => 'l', 'ŀ' => 'l', 'ł' => 'l', 'Ñ' => 'N', 'Ń' => 'N', 'Ņ' => 'N', 'Ň' => 'N', 'ñ' => 'n', 'ń' => 'n', 'ņ' => 'n', 'ň' => 'n', 'ʼn' => 'n', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ō' => 'O', 'Ŏ' => 'O', 'Ǒ' => 'O', 'Ő' => 'O', 'Ơ' => 'O', 'Ø' => 'O', 'Ǿ' => 'O', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ō' => 'o', 'ŏ' => 'o', 'ǒ' => 'o', 'ő' => 'o', 'ơ' => 'o', 'ø' => 'o', 'ǿ' => 'o', 'º' => 'o', 'Ŕ' => 'R', 'Ŗ' => 'R', 'Ř' => 'R', 'ŕ' => 'r', 'ŗ' => 'r', 'ř' => 'r', 'Ś' => 'S', 'Ŝ' => 'S', 'Ş' => 'S', 'Ș' => 'S', 'Š' => 'S', 'ẞ' => 'SS', 'ś' => 's', 'ŝ' => 's', 'ş' => 's', 'ș' => 's', 'š' => 's', 'ſ' => 's', 'Ţ' => 'T', 'Ț' => 'T', 'Ť' => 'T', 'Ŧ' => 'T', 'ţ' => 't', 'ț' => 't', 'ť' => 't', 'ŧ' => 't', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ũ' => 'U', 'Ū' => 'U', 'Ŭ' => 'U', 'Ů' => 'U', 'Ű' => 'U', 'Ų' => 'U', 'Ư' => 'U', 'Ǔ' => 'U', 'Ǖ' => 'U', 'Ǘ' => 'U', 'Ǚ' => 'U', 'Ǜ' => 'U', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ũ' => 'u', 'ū' => 'u', 'ŭ' => 'u', 'ů' => 'u', 'ű' => 'u', 'ų' => 'u', 'ư' => 'u', 'ǔ' => 'u', 'ǖ' => 'u', 'ǘ' => 'u', 'ǚ' => 'u', 'ǜ' => 'u', 'Ý' => 'Y', 'Ÿ' => 'Y', 'Ŷ' => 'Y', 'ý' => 'y', 'ÿ' => 'y', 'ŷ' => 'y', 'Ŵ' => 'W', 'ŵ' => 'w', 'Ź' => 'Z', 'Ż' => 'Z', 'Ž' => 'Z', 'ź' => 'z', 'ż' => 'z', 'ž' => 'z', 'Æ' => 'AE', 'Ǽ' => 'AE', 'ß' => 'ss', 'IJ' => 'IJ', 'ij' => 'ij', 'Œ' => 'OE', 'ƒ' => 'f', 'Þ' => 'TH', 'þ' => 'th', 'Є' => 'Ye', 'є' => 'ye', ]
$_uninflected ¶
Words that should not be inflected
[ '.*[nrlm]ese', '.*data', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'feedback', 'stadia', '.*?media', 'chassis', 'clippers', 'debris', 'diabetes', 'equipment', 'gallows', 'graffiti', 'headquarters', 'information', 'innings', 'news', 'nexus', 'pokemon', 'proceedings', 'research', 'sea[- ]bass', 'series', 'species', 'weather' ]