Class Inflector

Pluralize and singularize English words.

Inflector pluralizes and singularizes English nouns. Used by CakePHP's naming conventions throughout the framework.

Method Detail

_cachesource 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

string|boolean
Inflected value on cache hit or false on cache miss.

camelizesource 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

string
CamelizedStringLikeThis.

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

classifysource 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

string
Class name

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-table-and-class-name-forms

dasherizesource 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

string
Dashed version of the input string

delimitsource 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

string
delimited string

humanizesource 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

string
Human-readable string

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-human-readable-forms

pluralizesource public static

pluralize( string $word )

Return $word in plural form.

Parameters

string $word
Word in singular

Returns

string
Word in plural

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-plural-singular-forms

resetsource public static

reset( )

Clears Inflectors inflected value caches. And resets the inflection rules to the initial values.

rulessource 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.

singularizesource public static

singularize( string $word )

Return $word in singular form.

Parameters

string $word
Word in plural

Returns

string
Word in singular

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-plural-singular-forms

slugsource 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.

Parameters

string $string
the string you want to slug
string $replacement optional '-'
will replace keys in map

Returns

string
string

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-url-safe-strings

tableizesource 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

string
Name of the database table for given class

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-table-and-class-name-forms

underscoresource 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

string
underscore_version of the input string

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-camelcase-and-under-scored-forms

variablesource public static

variable( string $string )

Returns camelBacked version of an underscored string.

Parameters

string $string
String to convert.

Returns

string
in variable form

Link

http://book.cakephp.org/3.0/en/core-libraries/inflector.html#creating-variable-names

Properties summary

$_cachesource

protected static array

Method cache array.

[]

$_initialStatesource

protected static array

The initial state of Inflector so reset() works.

[]

$_irregularsource

protected static array

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'
]

$_pluralsource

protected static array

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',
    '/(?:([^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',
]

$_singularsource

protected static array

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' => ''
]

$_transliterationsource

protected static array

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',
]

$_uninflectedsource

protected static array

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',
    'proceedings', 'research', 'sea[- ]bass', 'series', 'species', 'weather'
]

© 2005–2016 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.
http://api.cakephp.org/3.1/class-Cake.Utility.Inflector.html