added arr class and tweaked input class.
This commit is contained in:
parent
3038ed7a49
commit
d802ae8386
|
@ -0,0 +1,23 @@
|
|||
<?php namespace System;
|
||||
|
||||
class Arr {
|
||||
|
||||
/**
|
||||
* Get an item from an array.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $default
|
||||
* @param array $array
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($key, $default = null, $array = array())
|
||||
{
|
||||
if (is_null($key))
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
return (array_key_exists($key, $array)) ? $array[$key] : $default;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 @@ public static function plural($value)
|
|||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Check the plural forms for matches.
|
||||
// -----------------------------------------------------
|
||||
foreach (static::$plural as $pattern => $plural)
|
||||
{
|
||||
if (preg_match($pattern, $value))
|
||||
|
@ -172,25 +160,16 @@ public static function plural($value)
|
|||
*/
|
||||
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 @@ public static function singular($value)
|
|||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Check the singular forms for matches.
|
||||
// -----------------------------------------------------
|
||||
foreach (static::$singular as $pattern => $singular)
|
||||
{
|
||||
if (preg_match($pattern, $value))
|
||||
|
|
|
@ -10,7 +10,7 @@ class Input {
|
|||
public static $input;
|
||||
|
||||
/**
|
||||
* Determine if the input data contains an item or set of items.
|
||||
* Determine if the input data contains an item or set of items that are not empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -18,25 +18,7 @@ public static function has()
|
|||
{
|
||||
foreach (func_get_args() as $key)
|
||||
{
|
||||
if (is_null(static::get($key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the input data contains an item or set of items that are not empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function filled()
|
||||
{
|
||||
foreach (func_get_args() as $key)
|
||||
{
|
||||
if ( ! static::has($key) or trim((string) static::get($key)) == '')
|
||||
if (is_null(static::get($key)) or trim((string) static::get($key)) == '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -59,11 +41,12 @@ public static function get($key = null, $default = null)
|
|||
static::hydrate();
|
||||
}
|
||||
|
||||
return static::from_array(static::$input, $key, $default);
|
||||
return Arr::get($key, $default, static::$input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the old input data contains an item or set of items.
|
||||
* Determine if the old input data contains an item or set of
|
||||
* items that are not empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -71,25 +54,7 @@ public static function had()
|
|||
{
|
||||
foreach (func_get_args() as $key)
|
||||
{
|
||||
if (is_null(static::old($key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the old input data contains an item or set of items that are not empty.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function was_filled()
|
||||
{
|
||||
foreach (func_get_args() as $key)
|
||||
{
|
||||
if ( ! static::had($key) or trim((string) static::old($key)) == '')
|
||||
if (is_null(static::old($key)) or trim((string) static::old($key)) == '')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -112,25 +77,7 @@ public static function old($key = null, $default = null)
|
|||
throw new \Exception("Sessions must be enabled to retrieve old input data.");
|
||||
}
|
||||
|
||||
return static::from_array(Session::get('laravel_old_input', array()), $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array. If no key is specified, the entire array will be returned.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return string
|
||||
*/
|
||||
private static function from_array($array, $key, $default)
|
||||
{
|
||||
if (is_null($key))
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
return (array_key_exists($key, $array)) ? $array[$key] : $default;
|
||||
return Arr::get($key, $default, Session::get('laravel_old_input', array()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue