From a7e98e8e9a3f5999f49099c456b5b9b33da5a076 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 15 Oct 2011 22:38:43 -0500 Subject: [PATCH] fixing bugs and refactoring. --- laravel/config.php | 25 +++++++++++++++---------- laravel/cookie.php | 6 +++--- laravel/form.php | 18 ++++++++++++++---- laravel/input.php | 13 +------------ laravel/lang.php | 2 +- laravel/laravel.php | 4 ++-- laravel/str.php | 23 +++++++++++++++++++++-- 7 files changed, 57 insertions(+), 34 deletions(-) diff --git a/laravel/config.php b/laravel/config.php index 9fb762d9..9c2bfc4a 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -2,13 +2,6 @@ class Config { - /** - * The paths to the configuration files. - * - * @var array - */ - public static $paths = array(SYS_CONFIG_PATH, CONFIG_PATH); - /** * All of the loaded configuration items. * @@ -18,6 +11,13 @@ class Config { */ public static $items = array(); + /** + * The paths to the configuration files. + * + * @var array + */ + public static $paths = array(SYS_CONFIG_PATH, CONFIG_PATH); + /** * Determine if a configuration item or file exists. * @@ -114,9 +114,14 @@ protected static function parse($key) { $segments = explode('.', $key); - $key = (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null; - - return array($segments[0], $key); + if (count($segments) >= 2) + { + return array($segments[0], implode('.', array_slice($segments, 1))); + } + else + { + return array($segments[0], null); + } } /** diff --git a/laravel/cookie.php b/laravel/cookie.php index 2bf806b6..a41fcb4e 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -71,9 +71,9 @@ public static function forever($name, $value, $path = '/', $domain = null, $secu * * If a negative number of minutes is specified, the cookie will be deleted. * - * Note: This method's signature is very similar to the PHP setcookie method. - * However, you simply need to pass the number of minutes for which you - * wish the cookie to be valid. No funky time calculation is required. + * This method's signature is very similar to the PHP setcookie method. + * However, you simply need to pass the number of minutes for which you + * wish the cookie to be valid. No funky time calculation is required. * * @param string $name * @param string $value diff --git a/laravel/form.php b/laravel/form.php index 400f4683..ae9c4298 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -43,7 +43,9 @@ class Form { */ public static function open($action = null, $method = 'POST', $attributes = array(), $https = false) { - list($attributes['action'], $attributes['method']) = array(static::action($action, $https), static::method($method)); + $attributes['action'] = static::action($action, $https); + + $attributes['method'] = static::method($method); if ( ! array_key_exists('accept-charset', $attributes)) { @@ -433,7 +435,9 @@ public static function radio($name, $value = null, $checked = false, $attributes */ protected static function checkable($type, $name, $value, $checked, $attributes) { - $attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'checked' => ($checked) ? 'checked' : null)); + if ($checked) $attributes['checked'] = 'checked'; + + $attributes['id'] = static::id($name, $attributes); return static::input($type, $name, $value, $attributes); } @@ -508,9 +512,15 @@ public static function button($value, $attributes = array()) */ protected static function id($name, $attributes) { - if (array_key_exists('id', $attributes)) return $attributes['id']; + if (array_key_exists('id', $attributes)) + { + return $attributes['id']; + } - if (in_array($name, static::$labels)) return $name; + if (in_array($name, static::$labels)) + { + return $name; + } } } \ No newline at end of file diff --git a/laravel/input.php b/laravel/input.php index 83a1f43f..ad888782 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -7,7 +7,7 @@ class Input { * * @var array */ - protected static $input; + public static $input; /** * The key used to store old input in the session. @@ -16,17 +16,6 @@ class Input { */ const old_input = 'laravel_old_input'; - /** - * Set the input for the current request. - * - * @param array $input - * @return void - */ - public static function set($input) - { - static::$input = $input; - } - /** * Get all of the input data for the request. * diff --git a/laravel/lang.php b/laravel/lang.php index 9d6a1f1e..f475a2b6 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -72,7 +72,7 @@ protected function __construct($key, $replacements = array(), $language = null) */ public static function line($key, $replacements = array(), $language = null) { - if (is_null($language)) $language = Config::get('application.language'); + if (is_null($language)) $language = Config::$items['application']['language']; return new static($key, $replacements, $language); } diff --git a/laravel/laravel.php b/laravel/laravel.php index 8128e609..8aa41098 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -78,7 +78,7 @@ */ unset($input[Request::spoofer]); -Input::set($input); +Input::$input = $input; /** * Route the request to the proper route in the application. If a @@ -88,7 +88,7 @@ */ Routing\Filter::register(require APP_PATH.'filters'.EXT); -list($method, $uri) = array(Request::method(), Request::uri()); +list($uri, $method) = array(Request::uri(), Request::method()); $route = IoC::container()->core('routing.router')->route($method, $uri); diff --git a/laravel/str.php b/laravel/str.php index 8e64eb56..81c52407 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -188,9 +188,28 @@ public static function ascii($value) */ public static function random($length, $type = 'alnum') { - $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + return substr(str_shuffle(str_repeat(static::pool($type), 5)), 0, $length); + } - return substr(str_shuffle(str_repeat(($type == 'alnum') ? $pool.'0123456789' : $pool, 5)), 0, $length); + /** + * Get the character pool for a given type of random string. + * + * @param string $type + * @return string + */ + protected static function pool($type) + { + switch ($type) + { + case 'alpha': + return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + + case 'alnum': + return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + + default: + throw new \Exception("Invalid random string type [$type]."); + } } } \ No newline at end of file