Inflector
Joomla Framework String Inflector Class
The Inflector transforms words
since |
1.0 |
---|
Methods
__construct
Protected constructor.
__construct()
since |
1.0 |
---|
addCountableRule
Adds a countable word.
addCountableRule(mixed $data) : \Joomla\String\Inflector
since |
1.0 |
---|
Arguments
- $data
mixed
A string or an array of strings to add.
Response
\Joomla\String\Inflector
Returns this object to support chaining.
addPluraliseRule
Adds a pluralisation rule.
addPluraliseRule(mixed $data) : \Joomla\String\Inflector
since |
1.0 |
---|
Arguments
- $data
mixed
A string or an array of regex rules to add.
Response
\Joomla\String\Inflector
Returns this object to support chaining.
addRule
Adds inflection regex rules to the inflector.
addRule(mixed $data, string $ruleType) : void
since |
1.0 |
---|---|
throws |
|
Arguments
- $data
mixed
A string or an array of strings or regex rules to add.- $ruleType
string
The rule type: singular | plural | countable
addSingulariseRule
Adds a singularisation rule.
addSingulariseRule(mixed $data) : \Joomla\String\Inflector
since |
1.0 |
---|
Arguments
- $data
mixed
A string or an array of regex rules to add.
Response
\Joomla\String\Inflector
Returns this object to support chaining.
addWord
Adds a specific singular-plural pair for a word.
addWord(string $singular, string $plural = null) : \Joomla\String\Inflector
since |
1.0 |
---|
Arguments
- $singular
string
The singular form of the word.- $plural
string
The plural form of the word. If omitted, it is assumed the singular and plural are identical.
Response
\Joomla\String\Inflector
Returns this object to support chaining.
getCachedPlural
Gets an inflected word from the cache where the singular form is supplied.
getCachedPlural(string $singular) : string|boolean
since |
1.0 |
---|
Arguments
- $singular
string
A singular form of a word.
Response
string|boolean
The cached inflection or false if none found.
getCachedSingular
Gets an inflected word from the cache where the plural form is supplied.
getCachedSingular(string $plural) : string|boolean
since |
1.0 |
---|
Arguments
- $plural
string
A plural form of a word.
Response
string|boolean
The cached inflection or false if none found.
getInstance
Gets an instance of the JStringInflector singleton.
getInstance(boolean $new = false) : \Joomla\String\Inflector
since |
1.0 |
---|
Arguments
- $new
boolean
If true (default is false), returns a new instance regardless if one exists. This argument is mainly used for testing.
Response
isCountable
Checks if a word is countable.
isCountable(string $word) : boolean
since |
1.0 |
---|
Arguments
- $word
string
The string input.
Response
boolean
True if word is countable, false otherwise.
isPlural
Checks if a word is in a plural form.
isPlural(string $word) : boolean
since |
1.0 |
---|
Arguments
- $word
string
The string input.
Response
boolean
True if word is plural, false if not.
isSingular
Checks if a word is in a singular form.
isSingular(string $word) : boolean
since |
1.0 |
---|
Arguments
- $word
string
The string input.
Response
boolean
True if word is singular, false if not.
matchRegexRule
Execute a regex from rules.
matchRegexRule(string $word, string $ruleType) : string|boolean
The 'plural' rule type expects a singular word. The 'singular' rule type expects a plural word.
since |
1.0 |
---|
Arguments
- $word
string
The string input.- $ruleType
string
String (eg, singular|plural)
Response
string|boolean
An inflected string, or false if no rule could be applied.
setCache
Sets an inflected word in the cache.
setCache(string $singular, string $plural = null) : void
since |
1.0 |
---|
Arguments
- $singular
string
The singular form of the word.- $plural
string
The plural form of the word. If omitted, it is assumed the singular and plural are identical.
toPlural
Converts a word into its plural form.
toPlural(string $word) : string|boolean
since |
1.0 |
---|
Arguments
- $word
string
The singular word to pluralise.
Response
string|boolean
An inflected string, or false if no rule could be applied.
toSingular
Converts a word into its singular form.
toSingular(string $word) : string|boolean
since |
1.0 |
---|
Arguments
- $word
string
The plural word to singularise.
Response
string|boolean
An inflected string, or false if no rule could be applied.
Properties
rules
The inflector rules for singularisation, pluralisation and countability.
since |
1.0 |
---|
Type(s)
array
cache
Cached inflections.
The array is in the form [singular => plural]
since |
1.0 |
---|
Type(s)
array<mixed,string>