consolidated plural and plural_if into single method.

This commit is contained in:
Taylor Otwell 2011-11-07 23:30:43 -06:00
parent 0cd6966e15
commit c4aa6e6ba2
1 changed files with 19 additions and 13 deletions

View File

@ -115,25 +115,31 @@ class Inflector {
); );
/** /**
* Get the plural form of a word if the specified count is greater than one. * Convert a word to its plural form.
*
* Optionally, a count argument may be provided. If the count is greater than
* one, the word will be pluralized, otherwise the word will be returned from
* the method unchanged.
*
* <code>
* // Get the plural form of the word "child"
* $children = Inflector::plural('child');
*
* // Returns "comments"
* $comments = Inflector::plural('comment', 10);
*
* // Returns "comment"
* $comment = Inflector::plural('comment', 1);
* </code>
* *
* @param string $value * @param string $value
* @param int $count * @param int $count
* @return string * @return string
*/ */
public static function plural_if($value, $count) public static function plural($value, $count = null)
{ {
return ($count > 1) ? static::plural($value) : $value; if ( ! is_null($count) and $count <= 1) return $value;
}
/**
* Convert a word to its plural form.
*
* @param string $value
* @return string
*/
public static function plural($value)
{
$irregular = array_flip(static::$irregular); $irregular = array_flip(static::$irregular);
$plural = static::inflect($value, static::$plural_cache, $irregular, static::$plural); $plural = static::inflect($value, static::$plural_cache, $irregular, static::$plural);