Inflector
extends Base
in package
The Inflector transforms words from singular to plural and from plural to singular.
Original code from php-activerecord @link http://www.phpactiverecord.org/ who copied it from RoR's ActiveRecord @link http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html
Table of Contents
- $irregular : mixed
- $plural : mixed
- $reservedKeywords : array<string|int, mixed>
- Keyords are disallowed as model/class name.
- $singular : mixed
- $specialCharacters : string
- Special characters, which are not allowed in class or variable names.
- $uncountable : mixed
- __call() : mixed
- Report that the $method doesn't exist.
- __callStatic() : mixed
- Report that the $method doesn't exist.
- __get() : mixed
- Report that $property doesn't exist.
- __set() : mixed
- Report that $property doesn't exist and set the property to the given $value.
- __toString() : string
- The object is used as an string.
- camelBack() : string
- Return as camelBack word.
- camelCase() : string
- Return as CamelCased word.
- modelize() : string
- Returns a valid classname in PascalCase.
- pluralize() : string
- Returns the plural form of the word in the string.
- singularize() : string
- Returns the singular form of a word in a string.
- underscore() : string
- Return as lowercase underscored word.
- variablize() : string
- Returns a valid variable/property name.
Properties
$irregular
public
static mixed
$irregular
= ['move' => 'moves', 'foot' => 'feet', 'goose' => 'geese', 'sex' => 'sexes', 'child' => 'children', 'man' => 'men', 'tooth' => 'teeth', 'person' => 'people']
$plural
public
static mixed
$plural
= ['/(quiz)$/i' => '$1zes', '/^(ox)$/i' => '$1en', '/([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|([lr])f)$/i' => '$1$2ves', '/(shea|lea|loa|thie)f$/i' => '$1ves', '/sis$/i' => 'ses', '/([ti])um$/i' => '$1a', '/(tomat|potat|ech|her|vet)o$/i' => '$1oes', '/(bu)s$/i' => '$1ses', '/(alias)$/i' => '$1es', '/(octop)us$/i' => '$1i', '/(ax|test)is$/i' => '$1es', '/(us)$/i' => '$1es', '/s$/i' => 's', '/$/' => 's']
$reservedKeywords
Keyords are disallowed as model/class name.
public
static array<string|int, mixed>
$reservedKeywords
= [
// PHP Keywords
'__halt_compiler',
'abstract',
'and',
'array',
'as',
'break',
'callable',
'case',
'catch',
'class',
'clone',
'const',
'continue',
'declare',
'default',
'die',
'do',
'echo',
'else',
'elseif',
'empty',
'enddeclare',
'endfor',
'endforeach',
'endif',
'endswitch',
'endwhile',
'eval',
'exit',
'extends',
'final',
'for',
'foreach',
'function',
'global',
'goto',
'if',
'implements',
'include',
'include_once',
'instanceof',
'insteadof',
'interface',
'isset',
'list',
'namespace',
'new',
'or',
'print',
'private',
'protected',
'public',
'require',
'require_once',
'return',
'static',
'switch',
'throw',
'trait',
'try',
'unset',
'use',
'var',
'while',
'xor',
// Compile-time constants (converted to lowercase)
'__class__',
'__dir__',
'__file__',
'__function__',
'__line__',
'__method__',
'__namespace__',
'__trait__',
]
Tags
$singular
public
static mixed
$singular
= ['/(quiz)zes$/i' => '$1', '/(matr)ices$/i' => '$1ix', '/(vert|ind)ices$/i' => '$1ex', '/^(ox)en$/i' => '$1', '/(alias)es$/i' => '$1', '/(octop|vir)i$/i' => '$1us', '/(cris|ax|test)es$/i' => '$1is', '/(shoe)s$/i' => '$1', '/(o)es$/i' => '$1', '/(bus)es$/i' => '$1', '/([m|l])ice$/i' => '$1ouse', '/(x|ch|ss|sh)es$/i' => '$1', '/(m)ovies$/i' => '$1ovie', '/(s)eries$/i' => '$1eries', '/([^aeiouy]|qu)ies$/i' => '$1y', '/([lr])ves$/i' => '$1f', '/(tive)s$/i' => '$1', '/(hive)s$/i' => '$1', '/(li|wi|kni)ves$/i' => '$1fe', '/(shea|loa|lea|thie)ves$/i' => '$1f', '/(^analy)ses$/i' => '$1sis', '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '$1$2sis', '/([ti])a$/i' => '$1um', '/(n)ews$/i' => '$1ews', '/(h|bl)ouses$/i' => '$1ouse', '/(corpse)s$/i' => '$1', '/(us)es$/i' => '$1', '/s$/i' => '']
$specialCharacters
Special characters, which are not allowed in class or variable names.
public
static string
$specialCharacters
= ' +-=!@#$%^&*()<>?\'"[](){}`~\\:;,.'
$uncountable
public
static mixed
$uncountable
= ['sheep', 'fish', 'deer', 'series', 'species', 'money', 'rice', 'information', 'equipment']
Methods
__call()
Report that the $method doesn't exist.
public
__call(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__callStatic()
Report that the $method doesn't exist.
public
static __callStatic(string $method, array<string|int, mixed> $arguments) : mixed
Parameters
- $method : string
- $arguments : array<string|int, mixed>
Return values
mixed —__get()
Report that $property doesn't exist.
public
__get(string $property) : mixed
Parameters
- $property : string
Return values
mixed —__set()
Report that $property doesn't exist and set the property to the given $value.
public
__set(string $property, mixed $value) : mixed
Parameters
- $property : string
- $value : mixed
Return values
mixed —__toString()
The object is used as an string.
public
__toString() : string
Return values
string —camelBack()
Return as camelBack word.
public
static camelBack(string $lowerCaseAndUnderscoredWord) : string
cart_item => cartItem cartItem => cartItem
Parameters
- $lowerCaseAndUnderscoredWord : string
Return values
string —camelBack word
camelCase()
Return as CamelCased word.
public
static camelCase(string $lowerCaseAndUnderscoredWord) : string
cart_item => CartItem cartItem => CartItem
Parameters
- $lowerCaseAndUnderscoredWord : string
Return values
string —CamelCased word
modelize()
Returns a valid classname in PascalCase.
public
static modelize(string $name[, string $options = [] ]) : string
Examples: customer => Customer when options[singularizeLast] is enabled: customers => Customer cart_items => CartItem
Parameters
- $name : string
-
A (table) name
- $options : string = []
-
array( 'prefix' => Remove the given database/table prefix 'singularizeLast' => (bool) default: true )
Return values
string —pluralize()
Returns the plural form of the word in the string.
public
static pluralize(string $singular) : string
Parameters
- $singular : string
Return values
string —singularize()
Returns the singular form of a word in a string.
public
static singularize(string $plural) : string
Parameters
- $plural : string
Return values
string —underscore()
Return as lowercase underscored word.
public
static underscore(string $camelCasedWord) : string
CartItem => cart_item cartItem => cart_item
Parameters
- $camelCasedWord : string
Return values
string —underscored_word
variablize()
Returns a valid variable/property name.
public
static variablize(string $name) : string
Parameters
- $name : string
-
The (column) name