added arr class and tweaked input class.

This commit is contained in:
Taylor Otwell
2011-06-16 22:25:57 -05:00
parent 3038ed7a49
commit d802ae8386
3 changed files with 30 additions and 84 deletions

View File

@@ -121,25 +121,16 @@ class Inflector {
*/
public static function plural($value)
{
// -----------------------------------------------------
// If we have already pluralized this word, return it.
// -----------------------------------------------------
if (array_key_exists($value, static::$plural_cache))
{
return static::$plural_cache[$value];
}
// -----------------------------------------------------
// Are the singular and plural forms the same?
// -----------------------------------------------------
if (in_array(Str::lower($value), static::$uncountable))
{
return static::$plural_cache[$value] = $value;
}
// -----------------------------------------------------
// Is the plural form irregular?
// -----------------------------------------------------
foreach (static::$irregular as $pattern => $irregular)
{
$pattern = '/'.$pattern.'$/i';
@@ -150,9 +141,6 @@ class Inflector {
}
}
// -----------------------------------------------------
// Check the plural forms for matches.
// -----------------------------------------------------
foreach (static::$plural as $pattern => $plural)
{
if (preg_match($pattern, $value))
@@ -172,25 +160,16 @@ class Inflector {
*/
public static function singular($value)
{
// -----------------------------------------------------
// If we have already singularized this word, return it.
// -----------------------------------------------------
if (array_key_exists($value, static::$singular_cache))
{
return static::$singular_cache[$value];
}
// -----------------------------------------------------
// Are the singular and plural forms the same?
// -----------------------------------------------------
if (in_array(Str::lower($value), static::$uncountable))
{
return static::$singular_cache[$value] = $value;
}
// -----------------------------------------------------
// Is the plural form irregular?
// -----------------------------------------------------
foreach (static::$irregular as $irregular => $pattern)
{
$pattern = '/'.$pattern.'$/i';
@@ -201,9 +180,6 @@ class Inflector {
}
}
// -----------------------------------------------------
// Check the singular forms for matches.
// -----------------------------------------------------
foreach (static::$singular as $pattern => $singular)
{
if (preg_match($pattern, $value))