Refactor the inflector class.

This commit is contained in:
Taylor Otwell 2011-08-08 10:42:24 -05:00
parent e39ab9a0f9
commit afc80dd4d1
1 changed files with 16 additions and 4 deletions

View File

@ -121,9 +121,15 @@ class Inflector {
*/ */
public static function plural($value) public static function plural($value)
{ {
if (array_key_exists($value, static::$plural_cache)) return static::$plural_cache[$value]; if (array_key_exists($value, static::$plural_cache))
{
return static::$plural_cache[$value];
}
if (in_array(strtolower($value), static::$uncountable)) return static::$plural_cache[$value] = $value; if (in_array(strtolower($value), static::$uncountable))
{
return static::$plural_cache[$value] = $value;
}
foreach (static::$irregular as $pattern => $irregular) foreach (static::$irregular as $pattern => $irregular)
{ {
@ -154,9 +160,15 @@ public static function plural($value)
*/ */
public static function singular($value) public static function singular($value)
{ {
if (array_key_exists($value, static::$singular_cache)) return static::$singular_cache[$value]; if (array_key_exists($value, static::$singular_cache))
{
return static::$singular_cache[$value];
}
if (in_array(strtolower($value), static::$uncountable)) return static::$singular_cache[$value] = $value; if (in_array(strtolower($value), static::$uncountable))
{
return static::$singular_cache[$value] = $value;
}
foreach (static::$irregular as $irregular => $pattern) foreach (static::$irregular as $irregular => $pattern)
{ {