Commit d802ae83 authored by Taylor Otwell's avatar Taylor Otwell

added arr class and tweaked input class.

parent 3038ed7a
<?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;
}
}
\ No newline at end of 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))
......
......@@ -9,34 +9,16 @@ class Input {
*/
public static $input;
/**
* Determine if the input data contains an item or set of items.
*
* @return bool
*/
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()
public static function has()
{
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 @@ class Input {
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 @@ class Input {
{
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 @@ class Input {
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()));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment