PHP Class lithium\util\Inflector

Under_score a CamelCased word and vice versa. Replace spaces and special characters. Create a human readable word from the others. Used when consistency in naming conventions must be enforced.
Datei anzeigen Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Property Type Description
$_camelized array Contains a cache map of previously camelized words.
$_humanized array Contains a cache map of previously humanized words.
$_plural Contains the list of pluralization rules.
$_pluralized array Contains a cache map of previously pluralized words.
$_singular Contains the list of pluralization rules.
$_singularized array Contains a cache map of previously singularized words.
$_transliteration array Contains a default map of accented and special characters to ASCII characters. Can be extended or added to using Inflector::rules().
$_underscored array Contains a cache map of previously underscored words.
$_uninflected array Indexed array of words which are the same in both singular and plural form. You can add rules to this list using Inflector::rules().

Public Methods

Method Description
camelize ( string $word, boolean $cased = true ) : string Takes a under_scored word and turns it into a CamelCased or camelBack word
classify ( string $tableName ) : string Takes a under_scored table name and returns corresponding class name.
humanize ( string $word, string $separator = '_' ) : string Takes an under_scored version of a word and turns it into an human- readable form by replacing underscores with a space, and by upper casing the initial character.
pluralize ( string $word ) : string Changes the form of a word from singular to plural.
reset ( ) Clears local in-memory caches. Can be used to force a full-cache clear when updating inflection rules mid-way through request execution.
rules ( string $type, array $config = [] ) : mixed Gets or adds inflection and transliteration rules.
singularize ( string $word ) : string Changes the form of a word from plural to singular.
slug ( string $string, string $replacement = '-' ) : string Returns a string with all spaces converted to given replacement and non word characters removed. Maps special characters to ASCII using Inflector::$_transliteration, which can be updated using Inflector::rules().
tableize ( string $className ) : string Takes a CamelCased class name and returns corresponding under_scored table name.
underscore ( string $word ) : string Takes a CamelCased version of a word and turns it into an under_scored one.

Protected Methods

Method Description
_enclose ( string $string ) : string Enclose a string for preg matching.

Method Details

_enclose() protected static method

Enclose a string for preg matching.
protected static _enclose ( string $string ) : string
$string string String to enclose
return string Enclosed string

camelize() public static method

Takes a under_scored word and turns it into a CamelCased or camelBack word
public static camelize ( string $word, boolean $cased = true ) : string
$word string An under_scored or slugged word (i.e. `'red_bike'` or `'red-bike'`).
$cased boolean If false, first character is not upper cased
return string CamelCased version of the word (i.e. `'RedBike'`).

classify() public static method

Takes a under_scored table name and returns corresponding class name.
public static classify ( string $tableName ) : string
$tableName string Under_scored and plural table name (i.e. `'posts'`).
return string CamelCased class name (i.e. `'Post'`).

humanize() public static method

Takes an under_scored version of a word and turns it into an human- readable form by replacing underscores with a space, and by upper casing the initial character.
public static humanize ( string $word, string $separator = '_' ) : string
$word string Under_scored version of a word (i.e. `'red_bike'`).
$separator string The separator character used in the initial string.
return string Human readable version of the word (i.e. `'Red Bike'`).

pluralize() public static method

Changes the form of a word from singular to plural.
public static pluralize ( string $word ) : string
$word string Word in singular form.
return string Word in plural form.

reset() public static method

Clears local in-memory caches. Can be used to force a full-cache clear when updating inflection rules mid-way through request execution.
public static reset ( )

rules() public static method

Gets or adds inflection and transliteration rules.
public static rules ( string $type, array $config = [] ) : mixed
$type string Either `'transliteration'`, `'uninflected'`, `'singular'` or `'plural'`.
$config array
return mixed If `$config` is empty, returns the rules list specified by `$type`, otherwise returns `null`.

singularize() public static method

Changes the form of a word from plural to singular.
public static singularize ( string $word ) : string
$word string Word in plural form.
return string Word in singular form.

slug() public static method

Returns a string with all spaces converted to given replacement and non word characters removed. Maps special characters to ASCII using Inflector::$_transliteration, which can be updated using Inflector::rules().
See also: lithium\util\Inflector::rules()
public static slug ( string $string, string $replacement = '-' ) : string
$string string An arbitrary string to convert.
$replacement string The replacement to use for spaces.
return string The converted string.

tableize() public static method

Takes a CamelCased class name and returns corresponding under_scored table name.
public static tableize ( string $className ) : string
$className string CamelCased class name (i.e. `'Post'`).
return string Under_scored and plural table name (i.e. `'posts'`).

underscore() public static method

Takes a CamelCased version of a word and turns it into an under_scored one.
public static underscore ( string $word ) : string
$word string CamelCased version of a word (i.e. `'RedBike'`).
return string Under_scored version of the workd (i.e. `'red_bike'`).

Property Details

$_camelized protected_oe static_oe property

Contains a cache map of previously camelized words.
protected static array $_camelized
return array

$_humanized protected_oe static_oe property

Contains a cache map of previously humanized words.
protected static array $_humanized
return array

$_plural protected_oe static_oe property

Contains the list of pluralization rules.
See also: lithium\util\Inflector::rules()
protected static $_plural

$_pluralized protected_oe static_oe property

Contains a cache map of previously pluralized words.
protected static array $_pluralized
return array

$_singular protected_oe static_oe property

Contains the list of pluralization rules.
See also: lithium\util\Inflector::rules()
protected static $_singular

$_singularized protected_oe static_oe property

Contains a cache map of previously singularized words.
protected static array $_singularized
return array

$_transliteration protected_oe static_oe property

Contains a default map of accented and special characters to ASCII characters. Can be extended or added to using Inflector::rules().
See also: lithium\util\Inflector::slug()
See also: lithium\util\Inflector::rules()
protected static array $_transliteration
return array

$_underscored protected_oe static_oe property

Contains a cache map of previously underscored words.
protected static array $_underscored
return array

$_uninflected protected_oe static_oe property

Indexed array of words which are the same in both singular and plural form. You can add rules to this list using Inflector::rules().
See also: lithium\util\Inflector::rules()
protected static array $_uninflected
return array