From 442904b277c6d25567baee65cc2cf8250b7536f5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 28 Sep 2011 22:12:41 -0500 Subject: [PATCH] refactoring. --- laravel/redirect.php | 2 +- laravel/request.php | 12 ++++++------ laravel/response.php | 8 +++++--- laravel/str.php | 14 ++++++-------- laravel/url.php | 4 ++-- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/laravel/redirect.php b/laravel/redirect.php index 20cf75ec..92f76432 100644 --- a/laravel/redirect.php +++ b/laravel/redirect.php @@ -61,7 +61,7 @@ public function with($key, $value) throw new \Exception('A session driver must be set before setting flash data.'); } - IoC::container()->resolve('laravel.session')->flash($key, $value); + IoC::container()->core('session')->flash($key, $value); return $this; } diff --git a/laravel/request.php b/laravel/request.php index 417257fa..8a6916a7 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -119,17 +119,17 @@ public function spoofed() */ public function ip($default = '0.0.0.0') { - if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) + if (isset($this->server['HTTP_X_FORWARDED_FOR'])) { - return $_SERVER['HTTP_X_FORWARDED_FOR']; + return $this->server['HTTP_X_FORWARDED_FOR']; } - elseif (isset($_SERVER['HTTP_CLIENT_IP'])) + elseif (isset($this->server['HTTP_CLIENT_IP'])) { - return $_SERVER['HTTP_CLIENT_IP']; + return $this->server['HTTP_CLIENT_IP']; } - elseif (isset($_SERVER['REMOTE_ADDR'])) + elseif (isset($this->server['REMOTE_ADDR'])) { - return $_SERVER['REMOTE_ADDR']; + return $this->server['REMOTE_ADDR']; } return ($default instanceof \Closure) ? call_user_func($default) : $default; diff --git a/laravel/response.php b/laravel/response.php index e210d633..7b9b099d 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -133,7 +133,7 @@ public static function make($content, $status = 200, $headers = array()) */ public static function view($view, $data = array()) { - return new static(IoC::container()->resolve('laravel.view')->make($view, $data)); + return new static(IoC::container()->core('view')->make($view, $data)); } /** @@ -153,7 +153,7 @@ public static function view($view, $data = array()) */ public static function with($name, $data = array()) { - return new static(IoC::container()->resolve('laravel.view')->of($name, $data)); + return new static(IoC::container()->core('view')->of($name, $data)); } /** @@ -177,7 +177,7 @@ public static function with($name, $data = array()) */ public static function error($code, $data = array()) { - return new static(IoC::container()->resolve('laravel.view')->make('error/'.$code, $data), $code); + return new static(IoC::container()->core('view')->make('error/'.$code, $data), $code); } /** @@ -274,6 +274,7 @@ public function send_headers() public function header($name, $value) { $this->headers[$name] = $value; + return $this; } @@ -286,6 +287,7 @@ public function header($name, $value) public function status($status) { $this->status = $status; + return $this; } diff --git a/laravel/str.php b/laravel/str.php index 62f7c8bd..6213211b 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -28,7 +28,7 @@ public static function upper($value) { if (function_exists('mb_strtoupper')) { - return mb_strtoupper($value, static::encoding()); + return mb_strtoupper($value, Config::get('application.encoding')); } return strtoupper($value); @@ -84,19 +84,17 @@ public static function ascii($value) /** * Generate a random alpha or alpha-numeric string. * - * Supported types: 'alpha_num' and 'alpha'. + * Supported types: 'alnum' and 'alpha'. * - * @param int $length + * @param int $length * @param string $type * @return string */ - public static function random($length = 16, $type = 'alpha_num') + public static function random($length, $type = 'alnum') { - $alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $pool = ($type == 'alpha_num') ? '0123456789'.$alpha : $alpha; - - return implode('', array_map(function() use ($pool) { return $pool[mt_rand(0, strlen($pool) - 1)]; }, range(0, $length - 1))); + return substr(str_shuffle(str_repeat(($type == 'alnum') ? $pool.'0123456789' : $pool, 5)), 0, $length); } } \ No newline at end of file diff --git a/laravel/url.php b/laravel/url.php index db301274..12c8c4f6 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -50,7 +50,7 @@ public static function to_secure($url = '') */ public static function to_asset($url, $https = null) { - if (is_null($https)) $https = IoC::container()->resolve('laravel.request')->secure(); + if (is_null($https)) $https = IoC::container()->core('request')->secure(); return str_replace('index.php/', '', static::to($url, $https)); } @@ -77,7 +77,7 @@ public static function to_asset($url, $https = null) */ public static function to_route($name, $parameters = array(), $https = false) { - if ( ! is_null($route = IoC::container()->resolve('laravel.routing.router')->find($name))) + if ( ! is_null($route = IoC::container()->core('routing.router')->find($name))) { $uris = explode(', ', key($route));