Class Inflector

Pluralize and singularize English words.

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

Package: Cake\Utility
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Link: http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html
Located at Cake/Utility/Inflector.php

Method Detail

_cachesource protected static

_cache( string $type , string $key , string $value false )

Cache inflected values, and return if already available

Parameters

string $type
Inflection type
string $key
Original value
string $value optional false
Inflected value

Returns

string
Inflected value, from cache

camelizesource public static

camelize( string $lowerCaseAndUnderscoredWord )

Returns the given lower_case_and_underscored_word as a CamelCased word.

Parameters

string $lowerCaseAndUnderscoredWord
Word to camelize

Returns

string
Camelized word. LikeThis.

Link

http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::camelize

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/2.0/en/core-utility-libraries/inflector.html#Inflector::classify

humanizesource public static

humanize( string $lowerCaseAndUnderscoredWord )

Returns the given underscored_word_group as a Human Readable Word Group. (Underscores are replaced by spaces and capitalized following words.)

Parameters

string $lowerCaseAndUnderscoredWord
String to be made more readable

Returns

string
Human-readable string

Link

http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::humanize

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/2.0/en/core-utility-libraries/inflector.html#Inflector::pluralize

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' or 'transliteration' $type.

Usage:

Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
Inflector::rules('plural', array(
    'rules' => array('/^(inflect)ors$/i' => '\1ables'),
    'uninflected' => array('dontinflectme'),
    'irregular' => array('red' => 'redlings')
));
Inflector::rules('transliteration', array('/å/' => 'aa'));

Parameters

string $type
The type of inflection, either 'plural', 'singular' 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/2.0/en/core-utility-libraries/inflector.html#Inflector::singularize

slugsource public static

slug( string $string , string $replacement '_' )

Returns a string with all spaces converted to underscores (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/2.0/en/core-utility-libraries/inflector.html#Inflector::slug

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/2.0/en/core-utility-libraries/inflector.html#Inflector::tableize

underscoresource public static

underscore( string $camelCasedWord )

Returns the given camelCasedWord as an underscored_word.

Parameters

string $camelCasedWord
Camel-cased word to be "underscorized"

Returns

string
Underscore-syntaxed version of the $camelCasedWord

Link

http://book.cakephp.org/2.0/en/core-utility-libraries/inflector.html#Inflector::underscore

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/2.0/en/core-utility-libraries/inflector.html#Inflector::variable

Properties summary

$_cachesource

protected static array

Method cache array.

array()

$_initialStatesource

protected static array

The initial state of Inflector so reset() works.

array()

$_pluralsource

protected static array

Plural inflector rules

array(
    'rules' => array(
        '/(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',
    ),
    'uninflected' => array(
        '.*[nrlm]ese',
        '.*data',
        '.*deer',
        '.*fish',
        '.*measles',
        '.*ois',
        '.*pox',
        '.*sheep',
        'people',
        'feedback',
        'stadia'
    ),
    'irregular' => array(
        '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',
        'sieve' => 'sieves'
    )
)

$_singularsource

protected static array

Singular inflector rules

array(
    'rules' => array(
        '/(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' => ''
    ),
    'uninflected' => array(
        '.*data',
        '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'feedback'
    ),
    'irregular' => array(
        'foes' => 'foe',
    )
)

$_transliterationsource

protected static array

Default map of accented and special characters to ASCII characters

array(
    '/À|Á|Â|Ã|Å|Ǻ|Ā|Ă|Ą|Ǎ/' => 'A',
    '/Æ|Ǽ/' => 'AE',
    '/Ä/' => 'Ae',
    '/Ç|Ć|Ĉ|Ċ|Č/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' => 'l',
    '/ñ|ń|ņ|ň|ʼn/' => 'n',
    '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º/' => 'o',
    '/ö|œ/' => 'oe',
    '/ŕ|ŗ|ř/' => 'r',
    '/ś|ŝ|ş|ș|š|ſ/' => 's',
    '/ß/' => 'ss',
    '/ţ|ț|ť|ŧ/' => 't',
    '/þ/' => 'th',
    '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ/' => 'u',
    '/ü/' => 'ue',
    '/ŵ/' => 'w',
    '/ý|ÿ|ŷ/' => 'y',
    '/є/' => 'ye',
    '/ї/' => 'yi',
    '/ź|ż|ž/' => 'z',
)

$_uninflectedsource

protected static array

Words that should not be inflected

array(
    'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus',
    'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps',
    'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder',
    'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
    'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings',
    'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media',
    'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese',
    'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese',
    'proceedings', 'rabies', 'research', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors',
    'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'swine', 'testes',
    'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', 'wildebeest',
    'Yengeese'
)

© 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/2.7/class-Inflector.html