Class Inflector
Pluralize and singularize English words.
Inflector pluralizes and singularizes English nouns. Used by CakePHP's naming conventions throughout the framework.
Property Summary
- 
        $_cache protected staticarrayMethod cache array. 
- 
        $_initialState protected staticarrayThe initial state of Inflector so reset() works. 
- 
        $_irregular protected staticarrayIrregular rules 
- 
        $_plural protected staticarrayPlural inflector rules 
- 
        $_singular protected staticarraySingular inflector rules 
- 
        $_transliteration protected staticarrayDefault map of accented and special characters to ASCII characters 
- 
        $_uninflected protected staticarrayWords that should not be inflected 
Method Summary
- 
          _cache() protected staticCache inflected values, and return if already available 
- 
          camelize() public staticReturns the input lower_case_delimited_string as a CamelCasedString. 
- 
          classify() public staticReturns Cake model class name ("Person" for the database table "people".) for given database table. 
- 
          dasherize() public staticReturns the input CamelCasedString as an dashed-string. 
- 
          delimit() public staticExpects a CamelCasedInputString, and produces a lower_case_delimited_string 
- 
          humanize() public staticReturns the input lower_case_delimited_string as 'A Human Readable String'. (Underscores are replaced by spaces and capitalized following words.) 
- 
          pluralize() public staticReturn $word in plural form. 
- 
          reset() public staticClears Inflectors inflected value caches. And resets the inflection rules to the initial values. 
- 
          rules() public staticAdds custom inflection $rules, of either 'plural', 'singular', 'uninflected', 'irregular' or 'transliteration' $type. 
- 
          singularize() public staticReturn $word in singular form. 
- 
          slug() public staticReturns a string with all spaces converted to dashes (by default), accented characters converted to non-accented characters, and non word characters removed. 
- 
          tableize() public staticReturns corresponding table name for given model $className. ("people" for the model class "Person"). 
- 
          underscore() public staticReturns the input CamelCasedString as an underscored_string. 
- 
          variable() public staticReturns camelBacked version of an underscored string. 
Method Detail
_cache() ¶ protected static
_cache(string $type, string $key, string|bool $value = false): string|boolCache inflected values, and return if already available
Parameters
- 
                string$type
- Inflection type 
- 
                string$key
- Original value 
- 
                string|bool$value optional
- Inflected value 
Returns
string|boolInflected value on cache hit or false on cache miss.
camelize() ¶ public static
camelize(string $string, string $delimiter = '_'): stringReturns 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): stringReturns 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): stringReturns 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 = '_'): stringExpects 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 = '_'): stringReturns 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): stringReturn $word in plural form.
Parameters
- 
                string$word
- Word in singular 
Returns
stringWord in plural
Links
reset() ¶ public static
reset(): voidClears Inflectors inflected value caches. And resets the inflection rules to the initial values.
Returns
voidrules() ¶ public static
rules(string $type, array $rules, bool $reset = false): voidAdds 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. 
- 
                bool$reset optional
- If true, will unset default inflections for all new rules that are being defined in $rules. 
Returns
voidsingularize() ¶ public static
singularize(string $word): stringReturn $word in singular form.
Parameters
- 
                string$word
- Word in plural 
Returns
stringWord in singular
Links
slug() ¶ public static
slug(string $string, string $replacement = '-'): stringReturns 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
stringLinks
tableize() ¶ public static
tableize(string $className): stringReturns 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): stringReturns 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): stringReturns camelBacked version of an underscored string.
Parameters
- 
                string$string
- String to convert. 
Returns
stringin variable form
Links
Property Detail
$_transliteration ¶ protected static
Default map of accented and special characters to ASCII characters
Type
array