\Cake\UtilityInflector

Pluralize and singularize English words.

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

Summary

Methods
Properties
Constants
reset()
rules()
pluralize()
singularize()
camelize()
underscore()
dasherize()
humanize()
delimit()
tableize()
classify()
variable()
slug()
No public properties found
No constants found
_cache()
$_plural
$_singular
$_irregular
$_uninflected
$_transliteration
$_cache
$_initialState
N/A
No private methods found
No private properties found
N/A

Properties

$_plural

$_plural : array

Plural inflector rules

Type

array

$_singular

$_singular : array

Singular inflector rules

Type

array

$_irregular

$_irregular : array

Irregular rules

Type

array

$_uninflected

$_uninflected : array

Words that should not be inflected

Type

array

$_transliteration

$_transliteration : array

Default map of accented and special characters to ASCII characters

Type

array

$_cache

$_cache : array

Method cache array.

Type

array

$_initialState

$_initialState : array

The initial state of Inflector so reset() works.

Type

array

Methods

reset()

reset() : void

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

rules()

rules(string  $type, array  $rules, boolean  $reset = false) : void

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

If true, will unset default inflections for all new rules that are being defined in $rules.

pluralize()

pluralize(string  $word) : string

Return $word in plural form.

Parameters

string $word

Word in singular

Returns

string —

Word in plural

singularize()

singularize(string  $word) : string

Return $word in singular form.

Parameters

string $word

Word in plural

Returns

string —

Word in singular

camelize()

camelize(string  $string, string  $delimiter = '_') : string

Returns the input lower_case_delimited_string as a CamelCasedString.

Parameters

string $string

String to camelize

string $delimiter

the delimiter in the input string

Returns

string —

CamelizedStringLikeThis.

underscore()

underscore(string  $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

dasherize()

dasherize(string  $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

humanize()

humanize(string  $string, string  $delimiter = '_') : string

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

the character to replace with a space

Returns

string —

Human-readable string

delimit()

delimit(string  $string, string  $delimiter = '_') : string

Expects a CamelCasedInputString, and produces a lower_case_delimited_string

Parameters

string $string

String to delimit

string $delimiter

the character to use as a delimiter

Returns

string —

delimited string

tableize()

tableize(string  $className) : string

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

classify()

classify(string  $tableName) : string

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

variable()

variable(string  $string) : string

Returns camelBacked version of an underscored string.

Parameters

string $string

String to convert.

Returns

string —

in variable form

slug()

slug(string  $string, string  $replacement = '-') : string

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

will replace keys in map

Returns

string

_cache()

_cache(string  $type, string  $key, string|boolean  $value = false) : string|false

Cache inflected values, and return if already available

Parameters

string $type

Inflection type

string $key

Original value

string|boolean $value

Inflected value

Returns

string|false —

Inflected value on cache hit or false on cache miss.