Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Copyright 2007-2017 Horde LLC (http://www.horde.org/)

License: http://www.horde.org/licenses/bsd
File Size: 437 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Horde_Support_Inflector:: (17 methods):
  __construct()
  uncountable()
  pluralize()
  singularize()
  camelize()
  titleize()
  underscore()
  dasherize()
  humanize()
  demodulize()
  tableize()
  classify()
  foreignKey()
  ordinalize()
  clearCache()
  getCache()
  setCache()


Class: Horde_Support_Inflector  - X-Ref

Horde Inflector class.

__construct()   X-Ref
Constructor.

Stores a map of the uncountable words for quicker checks.

uncountable($word)   X-Ref
Adds an uncountable word.

param: string $word The uncountable word.

pluralize($word)   X-Ref
Singular English word to pluralize.

param: string $word Word to pluralize.
return: string Plural form of $word.

singularize($word)   X-Ref
Plural English word to singularize.

param: string $word Word to singularize.
return: string Singular form of $word.

camelize($word, $firstLetter = 'upper')   X-Ref
Camel-cases a word.

param: string $word         The word to camel-case.
param: string $firstLetter  Whether to upper or lower case the first.
return: string Camelized $word

titleize($word)   X-Ref
Capitalizes all the words and replaces some characters in the string to
create a nicer looking title.

Titleize is meant for creating pretty output.

See:
- http://daringfireball.net/2008/05/title_case
- http://daringfireball.net/2008/08/title_case_update

Examples:
1. titleize("man from the boondocks") => "Man From The Boondocks"
2. titleize("x-men: the last stand")  => "X Men: The Last Stand"

underscore($camelCasedWord)   X-Ref
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"


dasherize($underscoredWord)   X-Ref
Replaces underscores with dashes in the string.

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

humanize($lowerCaseAndUnderscoredWord)   X-Ref
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"

demodulize($classNameInModule)   X-Ref
Removes the module part from the expression in the string.

Examples:
1. demodulize("Fax_Job") => "Job"
1. demodulize("User")    => "User"

tableize($className)   X-Ref
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"

classify($tableName)   X-Ref
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"

foreignKey($className, $separateClassNameAndIdWithUnderscore = true)   X-Ref
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"

ordinalize($number)   X-Ref
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"

clearCache()   X-Ref
Clears the inflection cache.


getCache($word, $rule)   X-Ref
Retuns a cached inflection.

return: string | false

setCache($word, $rule, $value)   X-Ref
Caches an inflection.

param: string $word   The word being inflected.
param: string $rule   The inflection rule.
param: string $value  The inflected value of $word.
return: string The inflected value