\Horde_Support_Inflector

Horde Inflector class.

Summary

Methods
Properties
Constants
__construct()
uncountable()
pluralize()
singularize()
camelize()
titleize()
underscore()
dasherize()
humanize()
demodulize()
tableize()
classify()
foreignKey()
ordinalize()
clearCache()
getCache()
setCache()
No public properties found
No constants found
No protected methods found
$_cache
$_pluralizationRules
$_singularizationRules
$_uncountables
N/A
No private methods found
No private properties found
N/A

Properties

$_cache

$_cache : array

Inflection cache

Type

array

$_pluralizationRules

$_pluralizationRules : array

Rules for pluralizing English nouns.

Type

array

$_singularizationRules

$_singularizationRules : array

Rules for singularizing English nouns.

Type

array

$_uncountables

$_uncountables : array

An array of words with the same singular and plural spellings.

Type

array

Methods

__construct()

__construct() 

Constructor.

Stores a map of the uncountable words for quicker checks.

uncountable()

uncountable(string  $word) 

Adds an uncountable word.

Parameters

string $word

The uncountable word.

pluralize()

pluralize(string  $word) : string

Singular English word to pluralize.

Parameters

string $word

Word to pluralize.

Returns

string —

Plural form of $word.

singularize()

singularize(string  $word) : string

Plural English word to singularize.

Parameters

string $word

Word to singularize.

Returns

string —

Singular form of $word.

camelize()

camelize(string  $word, string  $firstLetter = 'upper') : string

Camel-cases a word.

Parameters

string $word

The word to camel-case.

string $firstLetter

Whether to upper or lower case the first. letter of each slash-separated section.

Returns

string —

Camelized $word

underscore()

underscore(  $camelCasedWord) 

The reverse of camelize().

Makes an underscored form from the expression in the string.

Examples:

  1. underscore("ActiveRecord") => "active_record"
  2. underscore("ActiveRecord_Errors") => "active_record_errors"

Parameters

$camelCasedWord

dasherize()

dasherize(  $underscoredWord) 

Replaces underscores with dashes in the string.

Example:

  1. dasherize("puni_puni") => "puni-puni"

Parameters

$underscoredWord

humanize()

humanize(  $lowerCaseAndUnderscoredWord) 

Capitalizes the first word and turns underscores into spaces and strips _id.

Like titleize(), this is meant for creating pretty output.

Examples:

  1. humanize("employee_salary") => "Employee salary"
  2. humanize("author_id") => "Author"

Parameters

$lowerCaseAndUnderscoredWord

demodulize()

demodulize(  $classNameInModule) 

Removes the module part from the expression in the string.

Examples:

  1. demodulize("Fax_Job") => "Job"
  2. demodulize("User") => "User"

Parameters

$classNameInModule

tableize()

tableize(  $className) 

Creates the name of a table like Rails does for models to table names.

This method uses the pluralize() method on the last word in the string.

Examples:

  1. tableize("RawScaledScorer") => "raw_scaled_scorers"
  2. tableize("egg_and_ham") => "egg_and_hams"
  3. tableize("fancyCategory") => "fancy_categories"

Parameters

$className

classify()

classify(  $tableName) 

Creates a class name from a table name like Rails does for table names to models.

Examples:

  1. classify("egg_and_hams") => "EggAndHam"
  2. classify("post") => "Post"

Parameters

$tableName

foreignKey()

foreignKey(  $className,   $separateClassNameAndIdWithUnderscore = true) 

Creates a foreign key name from a class name.

$separateClassNameAndIdWithUnderscore sets whether the method should put '_' between the name and 'id'.

Examples:

  1. foreignKey("Message") => "message_id"
  2. foreignKey("Message", false) => "messageid"
  3. foreignKey("Fax_Job") => "fax_job_id"

Parameters

$className
$separateClassNameAndIdWithUnderscore

ordinalize()

ordinalize(  $number) 

Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.

Examples:

  1. ordinalize(1) => "1st"
  2. ordinalize(2) => "2nd"
  3. ordinalize(1002) => "1002nd"
  4. ordinalize(1003) => "1003rd"

Parameters

$number

clearCache()

clearCache() 

Clears the inflection cache.

getCache()

getCache(  $word,   $rule) : string

Retuns a cached inflection.

Parameters

$word
$rule

Returns

string —

| false

setCache()

setCache(string  $word, string  $rule, string  $value) : string

Caches an inflection.

Parameters

string $word

The word being inflected.

string $rule

The inflection rule.

string $value

The inflected value of $word.

Returns

string —

The inflected value