PHP Class FOF30\Inflector\Inflector

Show file Open project: akeeba/fof

Protected Properties

Property Type Description
$cache array Cache of pluralized and singularized nouns.
$rules array Rules for pluralizing and singularizing of nouns.

Public Methods

Method Description
addWord ( string $singular, string $plural ) : void Add a word to the cache, useful to make exceptions or to add words in other languages.
camelize ( string $word ) : string Returns given word as CamelCased.
deleteCache ( )
explode ( string $word ) : array Convert any "CamelCased" word into an array of strings
getPart ( string $string, integer $index, string $default = null ) : string Gets a part of a CamelCased word by index.
humanize ( string $word ) : string Returns a human-readable string from $word.
implode ( array $words ) : string Convert an array of strings into a "CamelCased" word.
isPlural ( string $string ) : boolean Check to see if an Enlish word is plural.
isSingular ( string $string ) : boolean Check to see if an English word is singular
pluralize ( string $word ) : string Singular English word to plural.
singularize ( string $word ) : string Plural English word to singular.
underscore ( string $word ) : string Converts a word "into_it_s_underscored_version"
variablize ( string $string ) : string Returns camelBacked version of a string. Same as camelize but first char is lowercased.

Method Details

addWord() public method

Add a word to the cache, useful to make exceptions or to add words in other languages.
public addWord ( string $singular, string $plural ) : void
$singular string word.
$plural string word.
return void

camelize() public method

Converts a word like "foo_bar" or "foo bar" to "FooBar". It will remove non alphanumeric characters from the word, so "who's online" will be converted to "WhoSOnline"
public camelize ( string $word ) : string
$word string Word to convert to camel case.
return string UpperCamelCasedWord

deleteCache() public method

public deleteCache ( )

explode() public method

Returns an array of strings each of which is a substring of string formed by splitting it at the camelcased letters.
public explode ( string $word ) : array
$word string Word to explode
return array Array of strings

getPart() public method

Use a negative index to start at the last part of the word (-1 is the last part)
public getPart ( string $string, integer $index, string $default = null ) : string
$string string Word
$index integer Index of the part
$default string Default value
return string

humanize() public method

Returns a human-readable string from $word, by replacing underscores with a space, and by upper-casing the initial character by default.
public humanize ( string $word ) : string
$word string String to "humanize"
return string Human-readable word

implode() public method

Convert an array of strings into a "CamelCased" word.
public implode ( array $words ) : string
$words array Array to implode
return string UpperCamelCasedWord

isPlural() public method

Check to see if an Enlish word is plural.
public isPlural ( string $string ) : boolean
$string string String to be checked.
return boolean

isSingular() public method

Check to see if an English word is singular
public isSingular ( string $string ) : boolean
$string string The word to check
return boolean

pluralize() public method

Singular English word to plural.
public pluralize ( string $word ) : string
$word string word to pluralize.
return string Plural noun.

singularize() public method

Plural English word to singular.
public singularize ( string $word ) : string
$word string Word to singularize.
return string Singular noun.

underscore() public method

Convert any "CamelCased" or "ordinary Word" into an "underscored_word".
public underscore ( string $word ) : string
$word string Word to underscore
return string Underscored word

variablize() public method

Returns camelBacked version of a string. Same as camelize but first char is lowercased.
See also: camelize
public variablize ( string $string ) : string
$string string String to be camelBacked.
return string

Property Details

$cache protected property

Cache of pluralized and singularized nouns.
protected array $cache
return array

$rules protected property

Rules for pluralizing and singularizing of nouns.
protected array $rules
return array