Inflector
in package
Doctrine inflector has static methods for inflecting text.
The methods in these classes are from several different sources collected across several different php projects and several different authors. The original author names and emails are not known.
Pluralize & Singularize implementation are borrowed from CakePHP with some modifications.
Tags
Table of Contents
- $cache : array<string|int, mixed>
- Method cache array.
- $initialState : array<string|int, mixed>
- The initial state of Inflector so reset() works.
- $plural : array<string|int, mixed>
- Plural inflector rules.
- $singular : array<string|int, mixed>
- Singular inflector rules.
- $uninflected : array<string|int, mixed>
- Words that should not be inflected.
- camelize() : string
- Camelizes a word. This uses the classify() method and turns the first character to lowercase.
- classify() : string
- Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
- pluralize() : string
- Returns a word in plural form.
- reset() : void
- Clears Inflectors inflected value caches, and resets the inflection rules to the initial values.
- rules() : void
- Adds custom inflection $rules, of either 'plural' or 'singular' $type.
- singularize() : string
- Returns a word in singular form.
- tableize() : string
- Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
- ucwords() : string
- Uppercases words with configurable delimeters between words.
Properties
$cache
Method cache array.
private
static array<string|int, mixed>
$cache
= array()
$initialState
The initial state of Inflector so reset() works.
private
static array<string|int, mixed>
$initialState
= array()
$plural
Plural inflector rules.
private
static array<string|int, mixed>
$plural
= array('rules' => array('/(s)tatus$/i' => '\1\2tatuses', '/(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|gulf)$/i' => '\1s', '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', '/sis$/i' => 'ses', '/([ti])um$/i' => '\1a', '/(p)erson$/i' => '\1eople', '/(m)an$/i' => '\1en', '/(c)hild$/i' => '\1hildren', '/(f)oot$/i' => '\1eet', '/(buffal|her|potat|tomat|volcan)o$/i' => '\1\2oes', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i', '/us$/i' => 'uses', '/(alias)$/i' => '\1es', '/(analys|ax|cris|test|thes)is$/i' => '\1es', '/s$/' => 's', '/^$/' => '', '/$/' => 's'), 'uninflected' => array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie', 'police'), 'irregular' => array('atlas' => 'atlases', 'axe' => 'axes', 'beef' => 'beefs', 'brother' => 'brothers', 'cafe' => 'cafes', 'chateau' => 'chateaux', 'niveau' => 'niveaux', 'child' => 'children', 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'criterion' => 'criteria', 'curriculum' => 'curricula', 'demo' => 'demos', 'domino' => 'dominoes', 'echo' => 'echoes', 'foot' => 'feet', 'fungus' => 'fungi', 'ganglion' => 'ganglions', 'genie' => 'genies', 'genus' => 'genera', 'graffito' => 'graffiti', 'hippopotamus' => 'hippopotami', 'hoof' => 'hoofs', 'human' => 'humans', 'iris' => 'irises', 'larva' => 'larvae', 'leaf' => 'leaves', 'loaf' => 'loaves', 'man' => 'men', 'medium' => 'media', 'memorandum' => 'memoranda', 'money' => 'monies', 'mongoose' => 'mongooses', 'motto' => 'mottoes', 'move' => 'moves', 'mythos' => 'mythoi', 'niche' => 'niches', 'nucleus' => 'nuclei', 'numen' => 'numina', 'occiput' => 'occiputs', 'octopus' => 'octopuses', 'opus' => 'opuses', 'ox' => 'oxen', 'passerby' => 'passersby', 'penis' => 'penises', 'person' => 'people', 'plateau' => 'plateaux', 'runner-up' => 'runners-up', 'sex' => 'sexes', 'soliloquy' => 'soliloquies', 'son-in-law' => 'sons-in-law', 'syllabus' => 'syllabi', 'testis' => 'testes', 'thief' => 'thieves', 'tooth' => 'teeth', 'tornado' => 'tornadoes', 'trilby' => 'trilbys', 'turf' => 'turfs', 'volcano' => 'volcanoes'))
$singular
Singular inflector rules.
private
static array<string|int, mixed>
$singular
= 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', '/(buffal|her|potat|tomat|volcan)oes$/i' => '\1o', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us', '/([ftw]ax)es/i' => '\1', '/(analys|ax|cris|test|thes)es$/i' => '\1is', '/(shoe|slave)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', '/([lr])ves$/i' => '\1f', '/(tive)s$/i' => '\1', '/(hive)s$/i' => '\1', '/(drive)s$/i' => '\1', '/(dive)s$/i' => '\1', '/([^fo])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', '/(f)eet$/i' => '\1oot', '/(n)ews$/i' => '\1\2ews', '/eaus$/' => 'eau', '/^(.*us)$/' => '\1', '/s$/i' => ''), 'uninflected' => array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', '.*ss', 'police', 'pants', 'clothes'), 'irregular' => array('caches' => 'cache', 'criteria' => 'criterion', 'curves' => 'curve', 'emphases' => 'emphasis', 'foes' => 'foe', 'hoaxes' => 'hoax', 'media' => 'medium', 'neuroses' => 'neurosis', 'waves' => 'wave', 'oases' => 'oasis'))
$uninflected
Words that should not be inflected.
private
static array<string|int, mixed>
$uninflected
= 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', 'Furniture', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti', 'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings', 'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'Luggage', 'mackerel', 'Maltese', '.*?media', 'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese', 'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese', 'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors', 'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'staff', 'swine', 'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting', 'wildebeest', 'Yengeese')
Methods
camelize()
Camelizes a word. This uses the classify() method and turns the first character to lowercase.
public
static camelize(string $word) : string
Parameters
- $word : string
-
The word to camelize.
Return values
string —The camelized word.
classify()
Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
public
static classify(string $word) : string
Parameters
- $word : string
-
The word to classify.
Return values
string —The classified word.
pluralize()
Returns a word in plural form.
public
static pluralize(string $word) : string
Parameters
- $word : string
-
The word in singular form.
Return values
string —The word in plural form.
reset()
Clears Inflectors inflected value caches, and resets the inflection rules to the initial values.
public
static reset() : void
Return values
void —rules()
Adds custom inflection $rules, of either 'plural' or 'singular' $type.
public
static rules(string $type, array<string|int, mixed> $rules[, bool $reset = false ]) : void
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') )); }}}
Parameters
- $type : string
-
The type of inflection, either 'plural' or 'singular'
- $rules : array<string|int, mixed>
-
An array of rules to be added.
- $reset : bool = false
-
If true, will unset default inflections for all new rules that are being defined in $rules.
Return values
void —singularize()
Returns a word in singular form.
public
static singularize(string $word) : string
Parameters
- $word : string
-
The word in plural form.
Return values
string —The word in singular form.
tableize()
Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
public
static tableize(string $word) : string
Parameters
- $word : string
-
The word to tableize.
Return values
string —The tableized word.
ucwords()
Uppercases words with configurable delimeters between words.
public
static ucwords(string $string[, string $delimiters = "
-" ]) : string
Takes a string and capitalizes all of the words, like PHP's built-in ucwords function. This extends that behavior, however, by allowing the word delimeters to be configured, rather than only separating on whitespace.
Here is an example:
Parameters
- $string : string
-
The string to operate on.
- $delimiters : string = " -"
-
A list of word separators.
Return values
string —The string with all delimeter-separated words capitalized.