fGrammarstatic classv1.0.0b6
Provides english word inflection, notation conversion, grammar helpers and internationlization support
| 1.0.0b6 | Added missing compose() method 3/3/10 |
|---|---|
| 1.0.0b5 | Fixed reset() to properly reset the singularization and pluralization rules 10/28/09 |
| 1.0.0b4 | Added caching for various methods - provided significant performance boost to ORM 6/15/09 |
| 1.0.0b3 | Changed replacement values in preg_replace() calls to be properly escaped 6/11/09 |
| 1.0.0b2 | Fixed a bug where some words would lose capitalization with pluralize() and singularize() 1/25/09 |
| 1.0.0b | The initial implementation 9/25/07 |
Static Methods
::addCamelUnderscoreRule() public
Adds a custom camelCase to underscore_notation and underscore_notation to camelCase rule
Signature
void addCamelUnderscoreRule( string $camel_case, string $underscore_notation )
Parameters
| string | $camel_case | The lower camelCase version of the string |
| string | $underscore_notation | The underscore_notation version of the string |
::addHumanizeRule() public
Adds a custom mapping of a non-humanized string to a humanized string for humanize()
Signature
void addHumanizeRule( string $non_humanized_string, string $humanized_string )
Parameters
| string | $non_humanized_string | The non-humanized string |
| string | $humanized_string | The humanized string |
::addSingularPluralRule() public
Adds a custom singular to plural and plural to singular rule for pluralize() and singularize()
Signature
void addSingularPluralRule( string $singular, string $plural )
Parameters
| string | $singular | The singular version of the noun |
| string | $plural | The plural version of the noun |
::camelize() public
Converts an underscore_notation, human-friendly or camelCase string to camelCase
Signature
string camelize( string $string, boolean $upper )
Parameters
| string | $string | The string to convert |
| boolean | $upper | If the camel case should be UpperCamelCase |
Returns
The converted string
::compose() protected
Composes text using fText if loaded
Signature
string compose( string $message, mixed $component )
Parameters
| string | $message | The message to compose |
| mixed | $component [, ... ] | A string or number to insert into the message |
Returns
The composed and possible translated message
::humanize() public
Makes an underscore_notation, camelCase, or human-friendly string into a human-friendly string
Signature
string humanize( string $string )
Parameters
| string | $string | The string to humanize |
Returns
The converted string
::inflectOnQuantity() public
Returns the singular or plural form of the word or based on the quantity specified
Signature
string inflectOnQuantity( mixed $quantity, string $singular_form, string $plural_form=NULL, boolean $use_words_for_single_digits=FALSE )
Parameters
| mixed | $quantity | The quantity (integer) or an array of objects to count |
| string | $singular_form | The string to be returned for when $quantity = 1 |
| string | $plural_form | The string to be returned for when $quantity != 1, use %d to place the quantity in the string |
| boolean | $use_words_for_single_digits | If the numbers 0 to 9 should be written out as words |
::joinArray() public
Returns the passed terms joined together using rule 2 from Strunk & White's 'The Elements of Style'
Signature
string joinArray( array $strings, string $type )
Parameters
| array | $strings | An array of strings to be joined together |
| string | $type | The type of join to perform, 'and' or 'or' |
Returns
The terms joined together
::pluralize() public
Returns the plural version of a singular noun
Signature
string pluralize( string $singular_noun )
Parameters
| string | $singular_noun | The singular noun to pluralize |
Returns
The pluralized noun
::registerJoinArrayCallback() public
Allows replacing the joinArray() function with a user defined function
This would be most useful for changing joinArray() to work with languages other than English.
Signature
void registerJoinArrayCallback( callback $callback )
Parameters
| callback | $callback | The function to replace joinArray() with - should accept the same parameters and return the same type |
::reset() internal public
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
Signature
void reset( )
::singularize() public
Returns the singular version of a plural noun
Signature
string singularize( string $plural_noun )
Parameters
| string | $plural_noun | The plural noun to singularize |
Returns
The singularized noun
::underscorize() public
Converts a camelCase, human-friendly or underscore_notation string to underscore_notation
Signature
string underscorize( string $string )
Parameters
| string | $string | The string to convert |
Returns
The converted string
