From b031fdf43d475ec81fa367ed08da4ae2df41d629 Mon Sep 17 00:00:00 2001 From: Bartosz Romanowski Date: Sat, 18 Jun 2011 23:01:52 +0200 Subject: [PATCH 01/66] APC cache driver --- system/cache/driver/apc.php | 80 +++++++++++++++++++++++++++++++++++++ system/cache/factory.php | 3 ++ 2 files changed, 83 insertions(+) create mode 100644 system/cache/driver/apc.php diff --git a/system/cache/driver/apc.php b/system/cache/driver/apc.php new file mode 100644 index 00000000..d689129d --- /dev/null +++ b/system/cache/driver/apc.php @@ -0,0 +1,80 @@ +get($key))); + } + + /** + * Get an item from the cache. + * + * @param string $key + * @param mixed $default + * @return mixed + */ + public function get($key, $default = null) + { + // -------------------------------------------------- + // If the item has already been loaded, return it. + // -------------------------------------------------- + if (array_key_exists($key, $this->items)) + { + return $this->items[$key]; + } + + // -------------------------------------------------- + // Attempt to the get the item from cache. + // -------------------------------------------------- + $cache = apc_fetch($key); + + // -------------------------------------------------- + // Verify that the item was retrieved. + // -------------------------------------------------- + if ($cache === false) + { + return $default; + } + + return $this->items[$key] = $cache; + } + + /** + * Write an item to the cache. + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return void + */ + public function put($key, $value, $minutes) + { + apc_store($key, $value, $minutes * 60); + } + + /** + * Delete an item from the cache. + * + * @param string $key + * @return void + */ + public function forget($key) + { + apc_delete($key); + } + +} \ No newline at end of file diff --git a/system/cache/factory.php b/system/cache/factory.php index 227d906c..245f4c85 100644 --- a/system/cache/factory.php +++ b/system/cache/factory.php @@ -18,6 +18,9 @@ class Factory { case 'memcached': return new Driver\Memcached; + case 'apc': + return new Driver\APC; + default: throw new \Exception("Cache driver [$driver] is not supported."); } From 2a2f699169eeec7ca7427a186db8cc1af07fbc67 Mon Sep 17 00:00:00 2001 From: Bartosz Romanowski Date: Sun, 19 Jun 2011 00:12:05 +0200 Subject: [PATCH 02/66] Added the cache key to avoid cache overwritting --- system/cache/driver/apc.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/cache/driver/apc.php b/system/cache/driver/apc.php index d689129d..54ba9304 100644 --- a/system/cache/driver/apc.php +++ b/system/cache/driver/apc.php @@ -40,7 +40,7 @@ class APC implements \System\Cache\Driver { // -------------------------------------------------- // Attempt to the get the item from cache. // -------------------------------------------------- - $cache = apc_fetch($key); + $cache = apc_fetch(\System\Config::get('cache.key').$key); // -------------------------------------------------- // Verify that the item was retrieved. @@ -63,7 +63,7 @@ class APC implements \System\Cache\Driver { */ public function put($key, $value, $minutes) { - apc_store($key, $value, $minutes * 60); + apc_store(\System\Config::get('cache.key').$key, $value, $minutes * 60); } /** @@ -74,7 +74,7 @@ class APC implements \System\Cache\Driver { */ public function forget($key) { - apc_delete($key); + apc_delete(\System\Config::get('cache.key').$key); } } \ No newline at end of file From 1ff5f8454585722fe7022291498237c66bea7068 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 18 Jun 2011 19:49:29 -0500 Subject: [PATCH 03/66] added apc driver notes in cache configuration file. --- application/config/cache.php | 28 ++++++++++++++-------------- system/cache/driver/apc.php | 9 --------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/application/config/cache.php b/application/config/cache.php index 1364446a..65ac2602 100644 --- a/application/config/cache.php +++ b/application/config/cache.php @@ -12,12 +12,24 @@ return array( | Caching can be used to increase the performance of your application | by storing commonly accessed data in memory or in a file. | - | Supported Drivers: 'file', 'memcached'. + | Supported Drivers: 'file', 'memcached', 'apc'. | */ 'driver' => 'file', + /* + |-------------------------------------------------------------------------- + | Cache Key + |-------------------------------------------------------------------------- + | + | This key will be prepended to items stored using Memcached and APC to + | prevent collisions with other applications on the server. + | + */ + + 'key' => 'laravel', + /* |-------------------------------------------------------------------------- | Memcached Servers @@ -35,18 +47,6 @@ return array( 'servers' => array( array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), - ), - - /* - |-------------------------------------------------------------------------- - | Memcached Key - |-------------------------------------------------------------------------- - | - | This key will be prepended to items stored using Memcached to avoid - | collisions with other applications on the server. - | - */ - - 'key' => 'laravel', + ), ); \ No newline at end of file diff --git a/system/cache/driver/apc.php b/system/cache/driver/apc.php index 54ba9304..195aa0ad 100644 --- a/system/cache/driver/apc.php +++ b/system/cache/driver/apc.php @@ -29,22 +29,13 @@ class APC implements \System\Cache\Driver { */ public function get($key, $default = null) { - // -------------------------------------------------- - // If the item has already been loaded, return it. - // -------------------------------------------------- if (array_key_exists($key, $this->items)) { return $this->items[$key]; } - // -------------------------------------------------- - // Attempt to the get the item from cache. - // -------------------------------------------------- $cache = apc_fetch(\System\Config::get('cache.key').$key); - // -------------------------------------------------- - // Verify that the item was retrieved. - // -------------------------------------------------- if ($cache === false) { return $default; From c77e8c5a36a5884c1f13b38ef4b81e943bea54a4 Mon Sep 17 00:00:00 2001 From: michaelowens Date: Sun, 19 Jun 2011 11:50:56 -0700 Subject: [PATCH 04/66] Fixed typo in View alias (missing backslash). --- application/config/application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/application.php b/application/config/application.php index fcafe721..0dd68ac8 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -118,7 +118,7 @@ return array( 'Session' => 'System\\Session', 'Str' => 'System\\Str', 'Text' => 'System\\Text', - 'View' => 'System\View', + 'View' => 'System\\View', ), ); \ No newline at end of file From dbc418c0d78b2d02cd1dfe8fe01369506095d4f2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 19 Jun 2011 22:49:01 -0500 Subject: [PATCH 05/66] changed Request::is to Request::route_is. --- system/request.php | 30 +++++++++++++++--------------- system/router.php | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/system/request.php b/system/request.php index 5e933bee..9b954bc6 100644 --- a/system/request.php +++ b/system/request.php @@ -74,17 +74,6 @@ class Request { return ($uri == '') ? '/' : Str::lower($uri); } - /** - * Determine if the route handling the request is a given name. - * - * @param string $name - * @return bool - */ - public static function is($name) - { - return (is_array(static::$route->callback) and isset(static::$route->callback['name']) and static::$route->callback['name'] === $name); - } - /** * Get the request method. * @@ -125,7 +114,7 @@ class Request { * * @return bool */ - public static function secure() + public static function is_secure() { return (static::protocol() == 'https'); } @@ -145,11 +134,22 @@ class Request { * * @return bool */ - public static function ajax() + public static function is_ajax() { return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and Str::lower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); } + /** + * Determine if the route handling the request is a given name. + * + * @param string $name + * @return bool + */ + public static function route_is($name) + { + return (is_array(static::$route->callback) and isset(static::$route->callback['name']) and static::$route->callback['name'] === $name); + } + /** * Magic Method to handle dynamic static methods. */ @@ -160,9 +160,9 @@ class Request { // // Example: Request::is_login() // -------------------------------------------------------------- - if (strpos($method, 'is_') === 0) + if (strpos($method, 'route_is_') === 0) { - return static::is(substr($method, 3)); + return static::route_is(substr($method, 9)); } } diff --git a/system/router.php b/system/router.php index 3bb18981..bb35cef2 100644 --- a/system/router.php +++ b/system/router.php @@ -56,7 +56,7 @@ class Router { if (preg_match('#^'.$key.'$#', $method.' '.$uri)) { - return Request::$route = new Route($key, $callback, Route\Parser::parameters($uri, $key)); + return Request::$route = new Route($keys, $callback, Route\Parser::parameters($uri, $key)); } } } From fcdcc656b45e24c7c031dadf05422fa9cbafca48 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 13:14:54 -0700 Subject: [PATCH 06/66] Add exception for SQLite databases that can't be found. --- system/db/connector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/db/connector.php b/system/db/connector.php index 602ec96e..39998060 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -41,6 +41,10 @@ class Connector { { return new \PDO('sqlite:'.$config->database, null, null, static::$options); } + else + { + throw new \Exception("SQLite database [".$config->database."] could not be found."); + } } // ----------------------------------------------------- // Connect to MySQL or Postgres. From adb583471b01475bc3d8ced119af71da3074c691 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 19:44:04 -0500 Subject: [PATCH 07/66] added Config::has and default value for Config::get. --- system/config.php | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/system/config.php b/system/config.php index f1180da4..d0105ac1 100644 --- a/system/config.php +++ b/system/config.php @@ -9,35 +9,57 @@ class Config { */ private static $items = array(); + /** + * Determine if a configuration item exists. + * + * @param string $key + * @return bool + */ + public static function has($key) + { + return ! is_null(static::get($key)); + } + /** * Get a configuration item. * * @param string $key + * @param string $default * @return mixed */ - public static function get($key) + public static function get($key, $default = null) { // ----------------------------------------------------- // If a dot is not present, we will just return the // entire configuration array. + // + // If the configuration file does not exist, the default + // value will be returned. // ----------------------------------------------------- if(strpos($key, '.') === false) { static::load($key); - return static::$items[$key]; + return (array_key_exists($key, static::$items)) ? static::$items[$key] : $default; } list($file, $key) = static::parse($key); static::load($file); - if (array_key_exists($key, static::$items[$file])) + // ----------------------------------------------------- + // If the file doesn't exist, return the default. + // ----------------------------------------------------- + if ( ! array_key_exists($file, static::$items)) { - return static::$items[$file][$key]; + return $default; } - throw new \Exception("Configuration item [$key] is not defined."); + // ----------------------------------------------------- + // Return the configuration item. If the item doesn't + // exist, the default value will be returned. + // ----------------------------------------------------- + return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : $default; } /** @@ -91,18 +113,13 @@ class Config { public static function load($file) { // ----------------------------------------------------- - // If we have already loaded the file, bail out. + // Bail out if already loaded or doesn't exist. // ----------------------------------------------------- - if (array_key_exists($file, static::$items)) + if (array_key_exists($file, static::$items) or ! file_exists($path = APP_PATH.'config/'.$file.EXT)) { return; } - if ( ! file_exists($path = APP_PATH.'config/'.$file.EXT)) - { - throw new \Exception("Configuration file [$file] does not exist."); - } - // ----------------------------------------------------- // Load the configuration array into the array of items. // The items array is keyed by filename. From 081a3e512f2720e2b062cd07ced3e3efffefbd37 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 20:11:17 -0500 Subject: [PATCH 08/66] initial commit of validation classes. --- system/str.php | 11 ++ system/validation/error_collector.php | 70 +++++++++ system/validation/rule.php | 93 ++++++++++++ system/validation/rules/acceptance_of.php | 39 +++++ system/validation/rules/confirmation_of.php | 25 +++ system/validation/rules/exclusion_of.php | 43 ++++++ system/validation/rules/format_of.php | 43 ++++++ system/validation/rules/inclusion_of.php | 43 ++++++ system/validation/rules/presence_of.php | 70 +++++++++ system/validation/rules/size_of.php | 160 ++++++++++++++++++++ system/validation/rules/uniqueness_of.php | 60 ++++++++ system/validation/rules/with_callback.php | 48 ++++++ system/validator.php | 94 ++++++++++++ 13 files changed, 799 insertions(+) create mode 100644 system/validation/error_collector.php create mode 100644 system/validation/rule.php create mode 100644 system/validation/rules/acceptance_of.php create mode 100644 system/validation/rules/confirmation_of.php create mode 100644 system/validation/rules/exclusion_of.php create mode 100644 system/validation/rules/format_of.php create mode 100644 system/validation/rules/inclusion_of.php create mode 100644 system/validation/rules/presence_of.php create mode 100644 system/validation/rules/size_of.php create mode 100644 system/validation/rules/uniqueness_of.php create mode 100644 system/validation/rules/with_callback.php create mode 100644 system/validator.php diff --git a/system/str.php b/system/str.php index 7ab40159..ec446c34 100644 --- a/system/str.php +++ b/system/str.php @@ -46,6 +46,17 @@ class Str { return (function_exists('mb_convert_case')) ? mb_convert_case($value, MB_CASE_TITLE, Config::get('application.encoding')) : ucwords(strtolower($value)); } + /** + * Get the length of a string. + * + * @param string $value + * @return int + */ + public static function length($value) + { + return function_exists('mb_strlen') ? mb_strlen($value, Config::get('application.encoding')) : strlen($value); + } + /** * Generate a random alpha or alpha-numeric string. * diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php new file mode 100644 index 00000000..13285ce8 --- /dev/null +++ b/system/validation/error_collector.php @@ -0,0 +1,70 @@ +messages = $messages; + } + + /** + * Add an error message to the collector. + * + * @param string $attribute + * @param string $message + * @return void + */ + public function add($attribute, $message) + { + $this->messages[$attribute][] = $message; + } + + /** + * Get the first error message for an attribute. + * + * @param string $attribute + * @return string + */ + public function first($attribute) + { + return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : ''; + } + + /** + * Get all of the error messages for an attribute. + * + * If no attribute is specified, all of the error messages will be returned. + * + * @param string $attribute + * @return array + */ + public function get($attribute = null) + { + if (is_null($attribute)) + { + $all = array(); + + foreach ($this->messages as $messages) + { + $all = array_merge($all, $messages); + } + + return $all; + } + + return (array_key_exists($attribute, $this->messages)) ? $this->messages[$attribute] : array(); + } + +} \ No newline at end of file diff --git a/system/validation/rule.php b/system/validation/rule.php new file mode 100644 index 00000000..d3e79289 --- /dev/null +++ b/system/validation/rule.php @@ -0,0 +1,93 @@ +attributes = $attributes; + } + + /** + * Run the validation rule. + * + * @param array $attributes + * @param Error_Collector $errors + * @return void + */ + public function validate($attributes, $errors) + { + if (is_null($this->message)) + { + throw new \Exception("An error message must be specified for every Eloquent validation rule."); + } + + foreach ($this->attributes as $attribute) + { + if ( ! $this->check($attribute, $attributes)) + { + $errors->add($attribute, $this->prepare_message($attribute)); + } + } + } + + /** + * Prepare the message to be added to the error collector. + * + * Attribute and size place-holders will replace with their actual values. + * + * @param string $attribute + * @return string + */ + private function prepare_message($attribute) + { + $message = $this->message; + + if (strpos($message, ':attribute')) + { + $message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get(), $message); + } + + if ($this instanceof Rules\Size_Of) + { + $message = str_replace(':max', $this->maximum, $message); + $message = str_replace(':min', $this->minimum, $message); + $message = str_replace(':size', $this->length, $message); + } + + return $message; + } + + /** + * Set the validation error message. + * + * @param string $message + * @return Rule + */ + public function message($message) + { + $this->message = $message; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/acceptance_of.php b/system/validation/rules/acceptance_of.php new file mode 100644 index 00000000..001c9a30 --- /dev/null +++ b/system/validation/rules/acceptance_of.php @@ -0,0 +1,39 @@ +accepts; + } + + /** + * Set the accepted value. + * + * @param string $value + * @return Acceptance_Of + */ + public function accepts($value) + { + $this->accepts = $value; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/confirmation_of.php b/system/validation/rules/confirmation_of.php new file mode 100644 index 00000000..02185cca --- /dev/null +++ b/system/validation/rules/confirmation_of.php @@ -0,0 +1,25 @@ +reserved); + } + + /** + * Set the reserved values for the attribute + * + * @param array $reserved + * @return Exclusion_Of + */ + public function from($reserved) + { + $this->reserved = $reserved; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/format_of.php b/system/validation/rules/format_of.php new file mode 100644 index 00000000..df0cd2de --- /dev/null +++ b/system/validation/rules/format_of.php @@ -0,0 +1,43 @@ +expression, $attributes[$attribute]); + } + + /** + * Set the regular expression. + * + * @param string $expression + * @return Format_Of + */ + public function with($expression) + { + $this->expression = $expression; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/inclusion_of.php b/system/validation/rules/inclusion_of.php new file mode 100644 index 00000000..db1e0afb --- /dev/null +++ b/system/validation/rules/inclusion_of.php @@ -0,0 +1,43 @@ +accepted); + } + + /** + * Set the accepted values for the attribute. + * + * @param array $accepted + * @return Inclusion_Of + */ + public function in($accepted) + { + $this->accepted = $accepted; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/presence_of.php b/system/validation/rules/presence_of.php new file mode 100644 index 00000000..06c05fd5 --- /dev/null +++ b/system/validation/rules/presence_of.php @@ -0,0 +1,70 @@ +allow_null) + { + return false; + } + + if (trim((string) $attributes[$attribute]) === '' and ! $this->allow_empty) + { + return false; + } + + return true; + } + + /** + * Allow an empty string to be considered present. + * + * @return Presence_Of + */ + public function allow_empty() + { + $this->allow_empty = true; + return $this; + } + + /** + * Allow a null to be considered present. + * + * @return Presence_Of + */ + public function allow_null() + { + $this->allow_null = true; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/size_of.php b/system/validation/rules/size_of.php new file mode 100644 index 00000000..8cefa1f6 --- /dev/null +++ b/system/validation/rules/size_of.php @@ -0,0 +1,160 @@ +check_number($attribute, $attributes); + } + else + { + return $this->check_string($attribute, $attributes); + } + } + + /** + * Evaluate the validity of a numeric attribute. + * + * @param string $attribute + * @param array $attributes + * @return void + */ + private function check_number($attribute, $attributes) + { + if ( ! is_null($this->length) and $attributes[$attribute] !== $this->length) + { + return false; + } + + if ( ! is_null($this->maximum) and $attributes[$attribute] > $this->maximum) + { + return false; + } + + if ( ! is_null($this->minimum and $attributes[$attribute] < $this->minimum)) + { + return false; + } + + return true; + } + + /** + * Evaluate the validity of a string attribute. + * + * @param string $attribute + * @param array $attributes + * @return void + */ + public function check_string($attribute, $attributes) + { + $value = trim((string) $attributes[$attribute]); + + if ( ! is_null($this->length) and Str::length($value) !== $this->length) + { + return false; + } + + if ( ! is_null($this->maximum) and Str::length($value) > $this->maximum) + { + return false; + } + + if ( ! is_null($this->minimum) and Str::length($value) < $this->minimum) + { + return false; + } + + return true; + } + + /** + * Set the exact size the attribute must be. + * + * @param int $length + * @return Size_Of + */ + public function is($length) + { + $this->length = $length; + return $this; + } + + /** + * Set the minimum and maximize size of the attribute. + * + * @param int $minimum + * @param int $maximum + * @return Size_Of + */ + public function between($minimum, $maximum) + { + $this->minimum = $minimum; + $this->maximum = $maximum; + + return $this; + } + + /** + * Set the minimum size the attribute. + * + * @param int $minimum + * @return Size_Of + */ + public function at_least($minimum) + { + $this->minimum = $minimum; + return $this; + } + + /** + * Set the maximum size the attribute. + * + * @param int $maximum + * @return Size_Of + */ + public function less_than($maximum) + { + $this->maximum = $maximum; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/uniqueness_of.php b/system/validation/rules/uniqueness_of.php new file mode 100644 index 00000000..938e813a --- /dev/null +++ b/system/validation/rules/uniqueness_of.php @@ -0,0 +1,60 @@ +column)) + { + $this->column = $attribute; + } + + return DB::table(Eloquent::table($this->table)->where($this->column, '=', $attributes[$attribute])->count() == 0; + } + + /** + * Set the database table and column. + * + * @param string $table + * @param string $column + * @return Uniqueness_Of + */ + public function on($table, $column = null) + { + $this->table = $table; + $this->column = $column; + + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/with_callback.php b/system/validation/rules/with_callback.php new file mode 100644 index 00000000..7ddbb75e --- /dev/null +++ b/system/validation/rules/with_callback.php @@ -0,0 +1,48 @@ +callback)) + { + throw new \Exception("A validation callback for the [$attribute] attribute is not callable."); + } + + return call_user_func($this->callback, $attributes[$attribute]); + } + + /** + * Set the validation callback. + * + * @param function $callback + * @return With_Callback + */ + public function using($callback) + { + $this->callback = $callback; + return $this; + } + +} \ No newline at end of file diff --git a/system/validator.php b/system/validator.php new file mode 100644 index 00000000..3264dae8 --- /dev/null +++ b/system/validator.php @@ -0,0 +1,94 @@ +attributes = ($target instanceof DB\Eloquent) ? $target->attributes : (array) $target; + + $this->errors = new Validation\Error_Collector; + } + + /** + * Create a new Eloquent validator instance. + * + * @param mixed $target + * @return Validator + */ + public static function of($target) + { + return new static($target); + } + + /** + * Determine if the model passes all of the validation rules. + * + * @return bool + */ + public function is_valid() + { + $this->errors->messages = array(); + + foreach ($this->rules as $rule) + { + // --------------------------------------------------------- + // The error collector is passed to the rule so that the + // rule may conveniently add error messages. + // --------------------------------------------------------- + $rule->validate($this->attributes, $this->errors); + } + + return count($this->errors->messages) === 0; + } + + /** + * Magic Method for dynamically creating validation rules. + */ + public function __call($method, $parameters) + { + // --------------------------------------------------------- + // Check if the validation rule is defined in the rules + // directory. If it is, create a new rule and return it. + // --------------------------------------------------------- + if (file_exists(SYS_PATH.'validation/rules/'.$method.EXT)) + { + $rule = '\\System\\Validation\\Rules\\'.$method; + + return $this->rules[] = new $rule($parameters); + } + + throw new \Exception("Method [$method] does not exist on Validator class."); + } + +} \ No newline at end of file From 9b8942fa1d54cc31d5503e5e40f8518a17edbf3e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 20:14:40 -0500 Subject: [PATCH 09/66] fixed equality check in validator. --- system/validator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validator.php b/system/validator.php index 3264dae8..a3991996 100644 --- a/system/validator.php +++ b/system/validator.php @@ -69,7 +69,7 @@ class Validator { $rule->validate($this->attributes, $this->errors); } - return count($this->errors->messages) === 0; + return count($this->errors->messages) == 0; } /** From 471ba2f8ae8a1b4299f45b237cabec1a5eb27822 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 20:22:52 -0500 Subject: [PATCH 10/66] added validator to aliases. --- application/config/application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/application/config/application.php b/application/config/application.php index 0dd68ac8..00fba80a 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -118,6 +118,7 @@ return array( 'Session' => 'System\\Session', 'Str' => 'System\\Str', 'Text' => 'System\\Text', + 'Validator' => 'System\\Validator', 'View' => 'System\\View', ), From 78301fb8c7ee10a3bb0d67ac911c56ba3d42ec96 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 22:22:52 -0500 Subject: [PATCH 11/66] fixed bugs in validation classes. --- system/validation/rules/format_of.php | 2 +- system/validation/rules/uniqueness_of.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/validation/rules/format_of.php b/system/validation/rules/format_of.php index df0cd2de..c615b443 100644 --- a/system/validation/rules/format_of.php +++ b/system/validation/rules/format_of.php @@ -34,7 +34,7 @@ class Format_Of extends Rule { * @param string $expression * @return Format_Of */ - public function with($expression) + public function using($expression) { $this->expression = $expression; return $this; diff --git a/system/validation/rules/uniqueness_of.php b/system/validation/rules/uniqueness_of.php index 938e813a..3e89fd49 100644 --- a/system/validation/rules/uniqueness_of.php +++ b/system/validation/rules/uniqueness_of.php @@ -39,7 +39,7 @@ class Uniqueness_Of extends Rule { $this->column = $attribute; } - return DB::table(Eloquent::table($this->table)->where($this->column, '=', $attributes[$attribute])->count() == 0; + return DB::table(Eloquent::table($this->table))->where($this->column, '=', $attributes[$attribute])->count() == 0; } /** From 0d10ab740b64d5491aaf73f08cf6b21bec38f849 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 22:34:53 -0500 Subject: [PATCH 12/66] changes to view class to have error collector. --- system/validation/error_collector.php | 11 +++++++++++ system/view.php | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php index 13285ce8..48fd8dbe 100644 --- a/system/validation/error_collector.php +++ b/system/validation/error_collector.php @@ -31,6 +31,17 @@ class Error_Collector { $this->messages[$attribute][] = $message; } + /** + * Determine if errors exist for an attribute. + * + * @param string $attribute + * @return bool + */ + public function has($attribute) + { + return $this->first($attribute) !== ''; + } + /** * Get the first error message for an attribute. * diff --git a/system/view.php b/system/view.php index 7a314211..0e93e51a 100644 --- a/system/view.php +++ b/system/view.php @@ -34,6 +34,16 @@ class View { { $this->view = $view; $this->data = $data; + + // ----------------------------------------------------- + // Every view has an error collector. This makes it + // convenient to check for any validation errors without + // worrying if the error collector is instantiated. + // + // If an error collector is in the session, it will + // be used as the error collector for the view. + // ----------------------------------------------------- + $this->data['errors'] = (Config::get('session.driver') != '' and Session::has('errors')) ? Session::get('errors') : new Validation\Error_Collector; } /** From 7f8c6863603951ba245853a9f8de821d9852e60c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 22:47:25 -0500 Subject: [PATCH 13/66] import lang class into validation rule. --- system/validation/rule.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/validation/rule.php b/system/validation/rule.php index d3e79289..c70c9c12 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -1,5 +1,7 @@ Date: Tue, 21 Jun 2011 22:50:09 -0500 Subject: [PATCH 14/66] removed called to eloquent in uniqueness_of. --- system/validation/rules/uniqueness_of.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validation/rules/uniqueness_of.php b/system/validation/rules/uniqueness_of.php index 3e89fd49..7e2a230b 100644 --- a/system/validation/rules/uniqueness_of.php +++ b/system/validation/rules/uniqueness_of.php @@ -39,7 +39,7 @@ class Uniqueness_Of extends Rule { $this->column = $attribute; } - return DB::table(Eloquent::table($this->table))->where($this->column, '=', $attributes[$attribute])->count() == 0; + return DB::table($this->table)->where($this->column, '=', $attributes[$attribute])->count() == 0; } /** From 3b63335c955ec1e6ad0fe8120f4d5a6fbc0d0928 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 21 Jun 2011 23:19:37 -0500 Subject: [PATCH 15/66] added apc session driver. --- application/config/session.php | 2 +- system/session/driver/apc.php | 49 ++++++++++++++++++++++++++++++++++ system/session/factory.php | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 system/session/driver/apc.php diff --git a/application/config/session.php b/application/config/session.php index 8a18cfce..be0e3e0d 100644 --- a/application/config/session.php +++ b/application/config/session.php @@ -12,7 +12,7 @@ return array( | Since HTTP is stateless, sessions are used to maintain "state" across | multiple requests from the same user of your application. | - | Supported Drivers: 'file', 'db', 'memcached'. + | Supported Drivers: 'file', 'db', 'memcached', 'apc'. | */ diff --git a/system/session/driver/apc.php b/system/session/driver/apc.php new file mode 100644 index 00000000..d240d015 --- /dev/null +++ b/system/session/driver/apc.php @@ -0,0 +1,49 @@ +get($id); + } + + /** + * Save a session. + * + * @param array $session + * @return void + */ + public function save($session) + { + \System\Cache::driver('apc')->put($session['id'], $session, \System\Config::get('session.lifetime')); + } + + /** + * Delete a session by ID. + * + * @param string $id + * @return void + */ + public function delete($id) + { + \System\Cache::driver('apc')->forget($id); + } + + /** + * Delete all expired sessions. + * + * @param int $expiration + * @return void + */ + public function sweep($expiration) + { + // APC sessions will expire automatically. + } + +} \ No newline at end of file diff --git a/system/session/factory.php b/system/session/factory.php index be0efa38..822cd074 100644 --- a/system/session/factory.php +++ b/system/session/factory.php @@ -21,6 +21,9 @@ class Factory { case 'memcached': return new Driver\Memcached; + case 'apc': + return new Driver\APC; + default: throw new \Exception("Session driver [$driver] is not supported."); } From eb3a5b0dc932003933073fb645194554fc405dd8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 06:43:48 -0700 Subject: [PATCH 16/66] Improving validation code and comments. --- system/validator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/validator.php b/system/validator.php index a3991996..1a26ca39 100644 --- a/system/validator.php +++ b/system/validator.php @@ -24,7 +24,7 @@ class Validator { public $rules = array(); /** - * Create a new Eloquent validator instance. + * Create a new Validator instance. * * @param mixed $target * @return void @@ -41,7 +41,7 @@ class Validator { } /** - * Create a new Eloquent validator instance. + * Create a new Validator instance. * * @param mixed $target * @return Validator @@ -52,7 +52,7 @@ class Validator { } /** - * Determine if the model passes all of the validation rules. + * Determine if the attributes pass all of the validation rules. * * @return bool */ From a536ceae72d1a24b130c60c4b8692a344a55507a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 06:52:10 -0700 Subject: [PATCH 17/66] Added default value to Lang::line()->get(). --- system/lang.php | 49 ++++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/system/lang.php b/system/lang.php index 6778c5eb..d74fd017 100644 --- a/system/lang.php +++ b/system/lang.php @@ -2,13 +2,6 @@ class Lang { - /** - * All of the loaded language files. - * - * @var array - */ - private static $loaded = array(); - /** * All of the loaded language lines. * @@ -55,24 +48,30 @@ class Lang { } /** - * Get the language line for a given language. + * Get the language line. * - * @param string $language + * @param mixed $default * @return string */ - public function get($language = null) + public function get($default = null) { - if (is_null($language)) - { - $language = Config::get('application.language'); - } + $language = Config::get('application.language'); list($file, $line) = $this->parse($this->key); $this->load($file, $language); + // -------------------------------------------------------------- + // If the language file did not exist, return the default value. + // -------------------------------------------------------------- + if ( ! array_key_exists($language.$file, static::$lines)) + { + return $default; + } + // -------------------------------------------------------------- // Get the language line from the appropriate file array. + // If the line doesn't exist, return the default value. // -------------------------------------------------------------- if (array_key_exists($line, static::$lines[$language.$file])) { @@ -80,7 +79,7 @@ class Lang { } else { - throw new \Exception("Language line [$line] does not exist for language [$language]"); + return $default; } // -------------------------------------------------------------- @@ -127,27 +126,15 @@ class Lang { private function load($file, $language) { // -------------------------------------------------------------- - // If we have already loaded the language file, bail out. + // If we have already loaded the language file or the file + // doesn't exist, bail out. // -------------------------------------------------------------- - if (in_array($language.$file, static::$loaded)) + if (array_key_exists($language.$file, static::$lines) or ! file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) { return; } - // -------------------------------------------------------------- - // Load the language file into the array of lines. The array - // is keyed by the language and file name. - // -------------------------------------------------------------- - if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) - { - static::$lines[$language.$file] = require $path; - } - else - { - throw new \Exception("Language file [$file] does not exist for language [$language]."); - } - - static::$loaded[] = $language.$file; + static::$lines[$language.$file] = require $path; } /** From 56e500419cbb520313ff01df533efa18fd383af1 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 06:55:58 -0700 Subject: [PATCH 18/66] Improving validation code and comments. --- system/validation/rule.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/system/validation/rule.php b/system/validation/rule.php index c70c9c12..4932eaf5 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -5,7 +5,7 @@ use System\Lang; abstract class Rule { /** - * The attributes being validated. + * The attributes being validated by the rule. * * @var array */ @@ -22,7 +22,6 @@ abstract class Rule { * Create a new validation Rule instance. * * @param array $attributes - * @param Validator $class * @return void */ public function __construct($attributes) @@ -39,11 +38,6 @@ abstract class Rule { */ public function validate($attributes, $errors) { - if (is_null($this->message)) - { - throw new \Exception("An error message must be specified for every Eloquent validation rule."); - } - foreach ($this->attributes as $attribute) { if ( ! $this->check($attribute, $attributes)) @@ -56,18 +50,28 @@ abstract class Rule { /** * Prepare the message to be added to the error collector. * - * Attribute and size place-holders will replace with their actual values. - * * @param string $attribute * @return string */ private function prepare_message($attribute) { + if (is_null($this->message)) + { + throw new \Exception("An error message must be specified for every Eloquent validation rule."); + } + $message = $this->message; + // --------------------------------------------------------- + // Replace any place-holders with their actual values. + // + // Attribute place-holders are loaded from the language + // directory. If the line doesn't exist, the attribute + // name will be used instead. + // --------------------------------------------------------- if (strpos($message, ':attribute')) { - $message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get(), $message); + $message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get($attribute), $message); } if ($this instanceof Rules\Size_Of) From 72c3f1859fa9800bd65b202d7bb48a9583312910 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:02:19 -0700 Subject: [PATCH 19/66] Improving validation code and comments. --- system/validation/rules/format_of.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validation/rules/format_of.php b/system/validation/rules/format_of.php index c615b443..4b969dc0 100644 --- a/system/validation/rules/format_of.php +++ b/system/validation/rules/format_of.php @@ -5,7 +5,7 @@ use System\Validation\Rule; class Format_Of extends Rule { /** - * The regular expression that will be used to evaluate the attribute. + * The regular expression that will be used to validate the attribute. * * @var string */ From 9d8c5d358777d312f87decbd6bc19ce43427fbee Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:03:36 -0700 Subject: [PATCH 20/66] Improving validation code and comments. --- system/validation/rules/presence_of.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validation/rules/presence_of.php b/system/validation/rules/presence_of.php index 06c05fd5..093b30c0 100644 --- a/system/validation/rules/presence_of.php +++ b/system/validation/rules/presence_of.php @@ -12,7 +12,7 @@ class Presence_Of extends Rule { public $allow_empty = false; /** - * Indicates a null should be considered present. + * Indicates null should be considered present. * * @var bool */ From 5956b90735826172e1ace2fe44a8ea75134a3ff8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:06:03 -0700 Subject: [PATCH 21/66] Improving validation code and comments. --- system/validation/rules/size_of.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validation/rules/size_of.php b/system/validation/rules/size_of.php index 8cefa1f6..1f7e861d 100644 --- a/system/validation/rules/size_of.php +++ b/system/validation/rules/size_of.php @@ -119,7 +119,7 @@ class Size_Of extends Rule { } /** - * Set the minimum and maximize size of the attribute. + * Set the minimum and maximum size of the attribute. * * @param int $minimum * @param int $maximum From 4d892ad3acf22c885b03bd040fad0c743f5fb7ee Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:07:49 -0700 Subject: [PATCH 22/66] Improving validation code and comments. --- system/validation/rules/uniqueness_of.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/validation/rules/uniqueness_of.php b/system/validation/rules/uniqueness_of.php index 7e2a230b..a693d556 100644 --- a/system/validation/rules/uniqueness_of.php +++ b/system/validation/rules/uniqueness_of.php @@ -1,7 +1,6 @@ Date: Wed, 22 Jun 2011 07:09:02 -0700 Subject: [PATCH 23/66] Improving validation code and comments. --- system/validation/rules/with_callback.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/validation/rules/with_callback.php b/system/validation/rules/with_callback.php index 7ddbb75e..8630b460 100644 --- a/system/validation/rules/with_callback.php +++ b/system/validation/rules/with_callback.php @@ -5,7 +5,7 @@ use System\Validation\Rule; class With_Callback extends Rule { /** - * The callback. + * The callback that will be used to validate the attribute. * * @var function */ @@ -27,7 +27,7 @@ class With_Callback extends Rule { if ( ! is_callable($this->callback)) { - throw new \Exception("A validation callback for the [$attribute] attribute is not callable."); + throw new \Exception("The validation callback for the [$attribute] attribute is not callable."); } return call_user_func($this->callback, $attributes[$attribute]); From 9f5367f32bc3564b1ddcf9398b69d2085c934352 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:26:35 -0700 Subject: [PATCH 24/66] Improving view class comments. --- system/view.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/view.php b/system/view.php index 0e93e51a..c4a58a88 100644 --- a/system/view.php +++ b/system/view.php @@ -95,6 +95,9 @@ class View { // We include the view into the local scope within a // try / catch block to catch any exceptions that may // occur while the view is rendering. + // + // Otherwise, a white screen of death will be shown + // when an exception occurs while rendering the view. // ----------------------------------------------------- try { @@ -111,9 +114,8 @@ class View { /** * Get the full path to the view. * - * Views are cascaded, so the application directory views - * will take precedence over the system directory's views - * of the same name. + * Views are cascaded, so the application directory views will take + * precedence over system directory views of the same name. * * @return string */ From dbeb2f4ddb6f54a37505807e3f9a0e54bfeaa027 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 07:27:11 -0700 Subject: [PATCH 25/66] Improving view class comments. --- system/view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/view.php b/system/view.php index c4a58a88..95b508cf 100644 --- a/system/view.php +++ b/system/view.php @@ -97,7 +97,7 @@ class View { // occur while the view is rendering. // // Otherwise, a white screen of death will be shown - // when an exception occurs while rendering the view. + // if an exception occurs while rendering the view. // ----------------------------------------------------- try { From d7aca820e521f716d18e54f33e01c466998a9ad8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 10:39:52 -0700 Subject: [PATCH 26/66] Clarified comments in Eloquent\Hydrator. --- system/db/eloquent/hydrator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/system/db/eloquent/hydrator.php b/system/db/eloquent/hydrator.php index ab068fed..f4ba7e02 100644 --- a/system/db/eloquent/hydrator.php +++ b/system/db/eloquent/hydrator.php @@ -78,8 +78,9 @@ class Hydrator { // ----------------------------------------------------- // Get the relationship Eloquent model. // - // We temporarily spoof the "belongs_to" key to allow - // the query to be fetched without any problems. + // We temporarily spoof the belongs_to key to allow the + // query to be fetched without any problems, since the + // belongs_to method actually gets the attribute. // ----------------------------------------------------- $eloquent->attributes[$spoof = $include.'_id'] = 0; From 3392971ce5b390a6488a783547a03d6e37e3b003 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 21:11:35 -0500 Subject: [PATCH 27/66] added dynamic finders to fluent query builder and eloquent. --- system/db/query.php | 14 +++++++++ system/db/query/dynamic.php | 60 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 system/db/query/dynamic.php diff --git a/system/db/query.php b/system/db/query.php index 3e28f20d..0d053554 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -500,6 +500,20 @@ class Query { */ public function __call($method, $parameters) { + // --------------------------------------------------------- + // Dynamic methods allows the building of very expressive + // queries. All dynamic methods start with "where_". + // + // Ex: DB::table('users')->where_email($email)->first(); + // --------------------------------------------------------- + if (strpos($method, 'where_') === 0) + { + return Query\Dynamic::build($method, $parameters, $this); + } + + // --------------------------------------------------------- + // Handle any of the aggregate functions. + // --------------------------------------------------------- if (in_array($method, array('count', 'min', 'max', 'avg', 'sum'))) { return ($method == 'count') ? $this->aggregate(Str::upper($method), '*') : $this->aggregate(Str::upper($method), $parameters[0]); diff --git a/system/db/query/dynamic.php b/system/db/query/dynamic.php new file mode 100644 index 00000000..ea90e2ea --- /dev/null +++ b/system/db/query/dynamic.php @@ -0,0 +1,60 @@ +where($segment, '=', $parameters[$index], $connector); + + $index++; + } + else + { + $connector = trim(Str::upper($segment), '_'); + } + } + + return $query; + } + +} \ No newline at end of file From a97b8b7fdaeccb7dcd85df001d009dd95565f1f9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 22 Jun 2011 21:30:48 -0500 Subject: [PATCH 28/66] added exception for wrong number of parameters to dynamic finders. --- system/db/query/dynamic.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/system/db/query/dynamic.php b/system/db/query/dynamic.php index ea90e2ea..5b507546 100644 --- a/system/db/query/dynamic.php +++ b/system/db/query/dynamic.php @@ -17,12 +17,12 @@ class Dynamic { // --------------------------------------------------------- // Strip the "where_" off of the method. // --------------------------------------------------------- - $method = substr($method, 6); + $finder = substr($method, 6); // --------------------------------------------------------- // Split the column names from the connectors. // --------------------------------------------------------- - $segments = preg_split('/(_and_|_or_)/i', $method, -1, PREG_SPLIT_DELIM_CAPTURE); + $segments = preg_split('/(_and_|_or_)/i', $finder, -1, PREG_SPLIT_DELIM_CAPTURE); // --------------------------------------------------------- // The connector variable will determine which connector @@ -44,6 +44,11 @@ class Dynamic { { if ($segment != '_and_' and $segment != '_or_') { + if ( ! array_key_exists($index, $parameters)) + { + throw new \Exception("Wrong number of parameters for dynamic finder [$method]."); + } + $query->where($segment, '=', $parameters[$index], $connector); $index++; From 3985a98f60df7aaec99a5aafb4ca48fac6410071 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jun 2011 11:33:42 -0700 Subject: [PATCH 29/66] Added Eloquent::all(). --- system/db/eloquent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/db/eloquent.php b/system/db/eloquent.php index be5d4d29..a5b383c5 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -477,7 +477,7 @@ abstract class Eloquent { { $model = static::make(get_called_class()); - if ($method == 'get') + if ($method == 'get' or $method == 'all') { return $model->_get(); } From 739068b00d8ff40992c0fe759c071cc7391cf311 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jun 2011 23:03:22 -0500 Subject: [PATCH 30/66] moved cache, db, logs, and sessions to the storage directory. --- application/{ => storage}/cache/.gitignore | 0 application/{ => storage}/db/.gitignore | 0 application/{ => storage}/logs/.gitignore | 0 application/{ => storage}/sessions/.gitignore | 0 system/cache/driver/file.php | 8 ++++---- system/db/connector.php | 2 +- system/log.php | 2 +- system/session/driver/file.php | 8 ++++---- 8 files changed, 10 insertions(+), 10 deletions(-) rename application/{ => storage}/cache/.gitignore (100%) rename application/{ => storage}/db/.gitignore (100%) rename application/{ => storage}/logs/.gitignore (100%) rename application/{ => storage}/sessions/.gitignore (100%) diff --git a/application/cache/.gitignore b/application/storage/cache/.gitignore similarity index 100% rename from application/cache/.gitignore rename to application/storage/cache/.gitignore diff --git a/application/db/.gitignore b/application/storage/db/.gitignore similarity index 100% rename from application/db/.gitignore rename to application/storage/db/.gitignore diff --git a/application/logs/.gitignore b/application/storage/logs/.gitignore similarity index 100% rename from application/logs/.gitignore rename to application/storage/logs/.gitignore diff --git a/application/sessions/.gitignore b/application/storage/sessions/.gitignore similarity index 100% rename from application/sessions/.gitignore rename to application/storage/sessions/.gitignore diff --git a/system/cache/driver/file.php b/system/cache/driver/file.php index 852bdb15..0994f75d 100644 --- a/system/cache/driver/file.php +++ b/system/cache/driver/file.php @@ -34,12 +34,12 @@ class File implements \System\Cache\Driver { return $this->items[$key]; } - if ( ! file_exists(APP_PATH.'cache/'.$key)) + if ( ! file_exists(APP_PATH.'storage/cache/'.$key)) { return $default; } - $cache = file_get_contents(APP_PATH.'cache/'.$key); + $cache = file_get_contents(APP_PATH.'storage/cache/'.$key); // -------------------------------------------------- // Has the cache expired? The UNIX expiration time @@ -65,7 +65,7 @@ class File implements \System\Cache\Driver { */ public function put($key, $value, $minutes) { - file_put_contents(APP_PATH.'cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); + file_put_contents(APP_PATH.'storage/cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); } /** @@ -76,7 +76,7 @@ class File implements \System\Cache\Driver { */ public function forget($key) { - @unlink(APP_PATH.'cache/'.$key); + @unlink(APP_PATH.'storage/cache/'.$key); } } \ No newline at end of file diff --git a/system/db/connector.php b/system/db/connector.php index 39998060..f494b4ed 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -33,7 +33,7 @@ class Connector { // If the database doesn't exist there, maybe the full // path was specified as the database name? // ----------------------------------------------------- - if (file_exists($path = APP_PATH.'db/'.$config->database.'.sqlite')) + if (file_exists($path = APP_PATH.'storage/db/'.$config->database.'.sqlite')) { return new \PDO('sqlite:'.$path, null, null, static::$options); } diff --git a/system/log.php b/system/log.php index 9c330a89..eba9d5d0 100644 --- a/system/log.php +++ b/system/log.php @@ -47,7 +47,7 @@ class Log { // ----------------------------------------------------- // Create the yearly and monthly directories if needed. // ----------------------------------------------------- - static::make_directory($directory = APP_PATH.'logs/'.date('Y')); + static::make_directory($directory = APP_PATH.'storage/logs/'.date('Y')); static::make_directory($directory .= '/'.date('m')); // ----------------------------------------------------- diff --git a/system/session/driver/file.php b/system/session/driver/file.php index d59f4258..47c70f10 100644 --- a/system/session/driver/file.php +++ b/system/session/driver/file.php @@ -10,7 +10,7 @@ class File implements \System\Session\Driver { */ public function load($id) { - if (file_exists($path = APP_PATH.'sessions/'.$id)) + if (file_exists($path = APP_PATH.'storage/sessions/'.$id)) { return unserialize(file_get_contents($path)); } @@ -24,7 +24,7 @@ class File implements \System\Session\Driver { */ public function save($session) { - file_put_contents(APP_PATH.'sessions/'.$session['id'], serialize($session), LOCK_EX); + file_put_contents(APP_PATH.'storage/sessions/'.$session['id'], serialize($session), LOCK_EX); } /** @@ -35,7 +35,7 @@ class File implements \System\Session\Driver { */ public function delete($id) { - @unlink(APP_PATH.'sessions/'.$id); + @unlink(APP_PATH.'storage/sessions/'.$id); } /** @@ -46,7 +46,7 @@ class File implements \System\Session\Driver { */ public function sweep($expiration) { - foreach (glob(APP_PATH.'sessions/*') as $file) + foreach (glob(APP_PATH.'storage/sessions/*') as $file) { if (filetype($file) == 'file' and filemtime($file) < $expiration) { From 6cb5af30244feef7c09db31abd063fae0d9233da Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jun 2011 23:08:09 -0500 Subject: [PATCH 31/66] added libraries directory and package class. --- application/libraries/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 application/libraries/.gitignore diff --git a/application/libraries/.gitignore b/application/libraries/.gitignore new file mode 100644 index 00000000..e69de29b From 8770473fd7c92d79a7abca72717fb4609a03b72b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jun 2011 23:12:34 -0500 Subject: [PATCH 32/66] removed package class, added package_path constant. --- public/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 8e6a9e70..09dc52ec 100644 --- a/public/index.php +++ b/public/index.php @@ -17,10 +17,11 @@ define('LARAVEL_START', microtime(true)); // -------------------------------------------------------------- // Define the framework paths. // -------------------------------------------------------------- +define('BASE_PATH', realpath('../').'/'); define('APP_PATH', realpath('../application').'/'); define('SYS_PATH', realpath('../system').'/'); -define('BASE_PATH', realpath('../').'/'); define('PUBLIC_PATH', realpath(__DIR__.'/')); +define('PACKAGE_PATH', APP_PATH.'packages/'); // -------------------------------------------------------------- // Define the PHP file extension. From 4a5190dfd9b73abc25346bb75d4548bad3a2b348 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 24 Jun 2011 23:42:53 -0500 Subject: [PATCH 33/66] changed loader to search in libraries instead of packages. --- system/loader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/loader.php b/system/loader.php index e7c963a8..a9491592 100644 --- a/system/loader.php +++ b/system/loader.php @@ -33,9 +33,9 @@ return function($class) { require $path; } // ---------------------------------------------------------- - // Is the class in the application/packages directory? + // Is the class in the application/libraries directory? // ---------------------------------------------------------- - elseif (file_exists($path = APP_PATH.'packages/'.$file.EXT)) + elseif (file_exists($path = APP_PATH.'libraries/'.$file.EXT)) { require $path; } From b7b258a10b8388f24ce9af56acefd4e1b45f649f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 25 Jun 2011 20:05:20 -0500 Subject: [PATCH 34/66] removed error collector bloat, switched to plain array. thanks mikelbring. --- system/html.php | 4 +- system/validation/error_collector.php | 81 --------------------------- system/validation/rule.php | 8 +-- system/validator.php | 10 ++-- system/view.php | 10 ---- 5 files changed, 10 insertions(+), 103 deletions(-) delete mode 100644 system/validation/error_collector.php diff --git a/system/html.php b/system/html.php index 298046f5..604a9ed2 100644 --- a/system/html.php +++ b/system/html.php @@ -21,7 +21,7 @@ class HTML { */ public static function script($url) { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -32,7 +32,7 @@ class HTML { */ public static function style($url, $media = 'all') { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php deleted file mode 100644 index 48fd8dbe..00000000 --- a/system/validation/error_collector.php +++ /dev/null @@ -1,81 +0,0 @@ -messages = $messages; - } - - /** - * Add an error message to the collector. - * - * @param string $attribute - * @param string $message - * @return void - */ - public function add($attribute, $message) - { - $this->messages[$attribute][] = $message; - } - - /** - * Determine if errors exist for an attribute. - * - * @param string $attribute - * @return bool - */ - public function has($attribute) - { - return $this->first($attribute) !== ''; - } - - /** - * Get the first error message for an attribute. - * - * @param string $attribute - * @return string - */ - public function first($attribute) - { - return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : ''; - } - - /** - * Get all of the error messages for an attribute. - * - * If no attribute is specified, all of the error messages will be returned. - * - * @param string $attribute - * @return array - */ - public function get($attribute = null) - { - if (is_null($attribute)) - { - $all = array(); - - foreach ($this->messages as $messages) - { - $all = array_merge($all, $messages); - } - - return $all; - } - - return (array_key_exists($attribute, $this->messages)) ? $this->messages[$attribute] : array(); - } - -} \ No newline at end of file diff --git a/system/validation/rule.php b/system/validation/rule.php index 4932eaf5..da3e6cf3 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -32,17 +32,17 @@ abstract class Rule { /** * Run the validation rule. * - * @param array $attributes - * @param Error_Collector $errors + * @param array $attributes + * @param array $errors * @return void */ - public function validate($attributes, $errors) + public function validate($attributes, &$errors) { foreach ($this->attributes as $attribute) { if ( ! $this->check($attribute, $attributes)) { - $errors->add($attribute, $this->prepare_message($attribute)); + $errors[$attribute][] = $this->prepare_message($attribute); } } } diff --git a/system/validator.php b/system/validator.php index 1a26ca39..c7e9a2bf 100644 --- a/system/validator.php +++ b/system/validator.php @@ -10,9 +10,9 @@ class Validator { public $attributes; /** - * The validation error collector. + * The validation errors * - * @var Error_Collector + * @var array */ public $errors; @@ -36,8 +36,6 @@ class Validator { // attributes as the validation attributes. // --------------------------------------------------------- $this->attributes = ($target instanceof DB\Eloquent) ? $target->attributes : (array) $target; - - $this->errors = new Validation\Error_Collector; } /** @@ -58,7 +56,7 @@ class Validator { */ public function is_valid() { - $this->errors->messages = array(); + $this->errors = array(); foreach ($this->rules as $rule) { @@ -69,7 +67,7 @@ class Validator { $rule->validate($this->attributes, $this->errors); } - return count($this->errors->messages) == 0; + return count($this->errors) == 0; } /** diff --git a/system/view.php b/system/view.php index 95b508cf..990b2dcd 100644 --- a/system/view.php +++ b/system/view.php @@ -34,16 +34,6 @@ class View { { $this->view = $view; $this->data = $data; - - // ----------------------------------------------------- - // Every view has an error collector. This makes it - // convenient to check for any validation errors without - // worrying if the error collector is instantiated. - // - // If an error collector is in the session, it will - // be used as the error collector for the view. - // ----------------------------------------------------- - $this->data['errors'] = (Config::get('session.driver') != '' and Session::has('errors')) ? Session::get('errors') : new Validation\Error_Collector; } /** From 0b7dbab0aff1271ac1097f8751fd8521309ce6e6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 25 Jun 2011 20:20:09 -0500 Subject: [PATCH 35/66] adjusted method order in request class. --- system/request.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/system/request.php b/system/request.php index 9b954bc6..064eef3b 100644 --- a/system/request.php +++ b/system/request.php @@ -109,16 +109,6 @@ class Request { } } - /** - * Determine if the request is using HTTPS. - * - * @return bool - */ - public static function is_secure() - { - return (static::protocol() == 'https'); - } - /** * Get the HTTP protocol for the request. * @@ -129,6 +119,16 @@ class Request { return (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; } + /** + * Determine if the request is using HTTPS. + * + * @return bool + */ + public static function is_secure() + { + return (static::protocol() == 'https'); + } + /** * Determine if the request is an AJAX request. * From 6410e83377fc07fcae1e75f1ba838d86dd2ed774 Mon Sep 17 00:00:00 2001 From: Michael Hasselbring Date: Sat, 25 Jun 2011 23:35:38 -0500 Subject: [PATCH 36/66] Created File::upload() --- system/file.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/system/file.php b/system/file.php index b46ca705..6eb42f2c 100644 --- a/system/file.php +++ b/system/file.php @@ -186,4 +186,15 @@ class File { return $response; } + /** + * Move uploaded file, Use $_FILES['file'] for $file + * + * @param array $file + * @param string $path + * @return bool + */ + public static function upload($file, $path) + { + return ( ! move_uploaded_file($file['tmp_name'], $path)) ? false : true; + } } \ No newline at end of file From abfaeaff4d8a6874fd92030afb8a0f0134854fb4 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 08:44:31 -0500 Subject: [PATCH 37/66] added upload_of validation rule. --- system/input.php | 12 +++++++ system/validation/rules/upload_of.php | 51 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 system/validation/rules/upload_of.php diff --git a/system/input.php b/system/input.php index 1e9fd973..b09ef673 100644 --- a/system/input.php +++ b/system/input.php @@ -69,6 +69,18 @@ class Input { return Arr::get(Session::get('laravel_old_input', array()), $key, $default); } + /** + * Get an item from the uploaded file data. + * + * @param string $key + * @param mixed $default + * @return array + */ + public static function file($key, $default = null) + { + return Arr::get($_FILES, $key, $default); + } + /** * Hydrate the input data for the request. * diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php new file mode 100644 index 00000000..cf1d3393 --- /dev/null +++ b/system/validation/rules/upload_of.php @@ -0,0 +1,51 @@ +maximum) and $file['size'] > $this->maximum) + { + return false; + } + + if ( ! is_null($this->extensions) and ! in_array(File::extension($file['name']), $this->extensions)) + { + return false; + } + + return true; + } + +} \ No newline at end of file From ee4dd5e987befb0001ab1eb438f8ba2292390895 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 08:48:12 -0500 Subject: [PATCH 38/66] tweaked File::upload. --- system/file.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/system/file.php b/system/file.php index 6eb42f2c..4e982bf4 100644 --- a/system/file.php +++ b/system/file.php @@ -187,14 +187,19 @@ class File { } /** - * Move uploaded file, Use $_FILES['file'] for $file + * Move an uploaded file to storage. * - * @param array $file - * @param string $path + * @param string $key + * @param string $path * @return bool */ - public static function upload($file, $path) + public static function upload($key, $path) { - return ( ! move_uploaded_file($file['tmp_name'], $path)) ? false : true; + if ( ! array_key_exists($key, $_FILES)) + { + return false; + } + + return move_uploaded_file($_FILES[$key]['tmp_name'], $path); } } \ No newline at end of file From 9f7da5cb396cb2059e5dadcf0a41af33bea3217c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 09:04:40 -0500 Subject: [PATCH 39/66] added methods for upload_of. --- system/validation/rules/upload_of.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php index cf1d3393..1b270aaa 100644 --- a/system/validation/rules/upload_of.php +++ b/system/validation/rules/upload_of.php @@ -46,6 +46,29 @@ class Upload_Of extends Rule { } return true; - } + } + + /** + * Set the acceptable file extensions. + * + * @return Upload_Of + */ + public function has_extension() + { + $this->extensions = func_get_args(); + return $this; + } + + /** + * Set the maximum file size in bytes. + * + * @param int $maximum + * @return Upload_Of + */ + public function less_than($maximum) + { + $this->maximum = $maximum; + return $this; + } } \ No newline at end of file From dc01b3c26e39696f344d1f2dc04aa6b3923f4f8e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 09:10:11 -0500 Subject: [PATCH 40/66] added default value to Input::file and defaulted Validator::make. --- system/input.php | 2 +- system/validator.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/system/input.php b/system/input.php index b09ef673..ffcc911c 100644 --- a/system/input.php +++ b/system/input.php @@ -76,7 +76,7 @@ class Input { * @param mixed $default * @return array */ - public static function file($key, $default = null) + public static function file($key = null, $default = null) { return Arr::get($_FILES, $key, $default); } diff --git a/system/validator.php b/system/validator.php index c7e9a2bf..cfb2a7f4 100644 --- a/system/validator.php +++ b/system/validator.php @@ -29,7 +29,7 @@ class Validator { * @param mixed $target * @return void */ - public function __construct($target) + public function __construct($target = array()) { // --------------------------------------------------------- // If the source is an Eloquent model, use the model's @@ -44,7 +44,7 @@ class Validator { * @param mixed $target * @return Validator */ - public static function of($target) + public static function make($target = array()) { return new static($target); } From 567da2419f886d71fa95f42b34aa46eddfa6091b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 09:19:54 -0500 Subject: [PATCH 41/66] added Form::open_multipart and tweaked Upload_of rule. --- system/form.php | 15 ++++++++++++++- system/validation/rules/upload_of.php | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/system/form.php b/system/form.php index 2e3ffb42..49d60b36 100644 --- a/system/form.php +++ b/system/form.php @@ -50,6 +50,20 @@ class Form { return $html.PHP_EOL; } + /** + * Open a HTML form that accepts file uploads. + * + * @param string $action + * @param string $method + * @param array $attributes + * @return string + */ + public static function open_multipart($action = null, $method = 'POST', $attributes = array()) + { + $attributes['enctype'] = 'multipart/form-data'; + return static::open($action, $method, $attributes); + } + /** * Close a HTML form. * @@ -100,7 +114,6 @@ class Form { public static function label($name, $value, $attributes = array()) { static::$labels[] = $name; - return ''.PHP_EOL; } diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php index 1b270aaa..e45dc56d 100644 --- a/system/validation/rules/upload_of.php +++ b/system/validation/rules/upload_of.php @@ -1,5 +1,6 @@ Date: Sun, 26 Jun 2011 11:59:51 -0500 Subject: [PATCH 42/66] added mime types, tweaked File::method to return first mime type. --- system/file.php | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/system/file.php b/system/file.php index 4e982bf4..fe275588 100644 --- a/system/file.php +++ b/system/file.php @@ -10,27 +10,27 @@ class File { public static $mimes = array( 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', - 'csv' => 'text/x-comma-separated-values', + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'), 'bin' => 'application/macbinary', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', - 'exe' => 'application/octet-stream', + 'exe' => array('application/octet-stream', 'application/x-msdownload'), 'class' => 'application/octet-stream', 'psd' => 'application/x-photoshop', 'so' => 'application/octet-stream', 'sea' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', - 'pdf' => 'application/pdf', + 'pdf' => array('application/pdf', 'application/x-download'), 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', - 'xls' => 'application/excel', - 'ppt' => 'application/powerpoint', + 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), 'wbxml' => 'application/wbxml', 'wmlc' => 'application/wmlc', 'dcr' => 'application/x-director', @@ -48,15 +48,15 @@ class File { 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'tar' => 'application/x-tar', - 'tgz' => 'application/x-tar', + 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', - 'zip' => 'application/x-zip', + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', - 'mp3' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', @@ -68,9 +68,9 @@ class File { 'wav' => 'audio/x-wav', 'bmp' => 'image/bmp', 'gif' => 'image/gif', - 'jpeg' => 'image/jpeg', - 'jpg' => 'image/jpeg', - 'jpe' => 'image/jpeg', + 'jpeg' => array('image/jpeg', 'image/pjpeg'), + 'jpg' => array('image/jpeg', 'image/pjpeg'), + 'jpe' => array('image/jpeg', 'image/pjpeg'), 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', @@ -80,7 +80,7 @@ class File { 'shtml' => 'text/html', 'txt' => 'text/plain', 'text' => 'text/plain', - 'log' => 'text/plain', + 'log' => array('text/plain', 'text/x-log'), 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'xml' => 'text/xml', @@ -95,9 +95,10 @@ class File { 'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'word' => 'application/msword', + 'word' => array('application/msword', 'application/octet-stream'), 'xl' => 'application/excel', - 'eml' => 'message/rfc822' + 'eml' => 'message/rfc822', + 'json' => array('application/json', 'text/json'), ); /** @@ -155,7 +156,12 @@ class File { */ public static function mime($extension, $default = 'application/octet-stream') { - return (array_key_exists($extension, static::$mimes)) ? static::$mimes[$extension] : $default; + if (array_key_exists($extension, static::$mimes)) + { + return (is_array(static::$mimes[$extension])) ? static::$mimes[$extension][0] : static::$mimes[$extension]; + } + + return $default; } /** From 6f5aca8d48f7a84b4c931ee3734b01052a0d325e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 12:26:15 -0500 Subject: [PATCH 43/66] added File::is method for accurately determining file type. --- system/file.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/system/file.php b/system/file.php index fe275588..8ed386db 100644 --- a/system/file.php +++ b/system/file.php @@ -39,7 +39,7 @@ class File { 'dvi' => 'application/x-dvi', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', - 'php' => 'application/x-httpd-php', + 'php' => array('application/x-httpd-php', 'text/x-php'), 'php4' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', 'phtml' => 'application/x-httpd-php', @@ -136,6 +136,25 @@ class File { return file_put_contents($path, $data, LOCK_EX | FILE_APPEND); } + /** + * Determine if a file is a given type. + * + * The Fileinfo PHP extension will be used to determine the MIME + * type of the file. Any extension in the File::$mimes array may + * be passed as a type. + */ + public static function is($extension, $path) + { + if ( ! array_key_exists($extension, static::$mimes)) + { + throw new \Exception("File extension [$extension] is unknown. Cannot determine file type."); + } + + $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); + + return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension]; + } + /** * Extract the extension from a file path. * From 8770d0aea1e95feb5a8ddfba3e12cb073b73274f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 12:28:48 -0500 Subject: [PATCH 44/66] tweaked File::is method. --- system/file.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/system/file.php b/system/file.php index 8ed386db..24402dc4 100644 --- a/system/file.php +++ b/system/file.php @@ -136,25 +136,6 @@ class File { return file_put_contents($path, $data, LOCK_EX | FILE_APPEND); } - /** - * Determine if a file is a given type. - * - * The Fileinfo PHP extension will be used to determine the MIME - * type of the file. Any extension in the File::$mimes array may - * be passed as a type. - */ - public static function is($extension, $path) - { - if ( ! array_key_exists($extension, static::$mimes)) - { - throw new \Exception("File extension [$extension] is unknown. Cannot determine file type."); - } - - $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); - - return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension]; - } - /** * Extract the extension from a file path. * @@ -183,6 +164,25 @@ class File { return $default; } + /** + * Determine if a file is a given type. + * + * The Fileinfo PHP extension will be used to determine the MIME + * type of the file. Any extension in the File::$mimes array may + * be passed as a type. + */ + public static function is($extension, $path) + { + if ( ! array_key_exists($extension, static::$mimes)) + { + throw new \Exception("File extension [$extension] is unknown. Cannot determine file type."); + } + + $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); + + return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension]; + } + /** * Create a response that will force a file to be downloaded. * From 2289570c9591d661eeb8a0d64a5f0b2cce3ca12e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 14:52:14 -0500 Subject: [PATCH 45/66] fixed exception message in validation/rule. --- system/validation/rule.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/validation/rule.php b/system/validation/rule.php index da3e6cf3..5eb4b4f8 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -57,7 +57,7 @@ abstract class Rule { { if (is_null($this->message)) { - throw new \Exception("An error message must be specified for every Eloquent validation rule."); + throw new \Exception("An error message must be specified for every validation rule."); } $message = $this->message; From bd3d8f634753865b6eb2f79cdd50cfee36c4b34f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 26 Jun 2011 16:17:41 -0500 Subject: [PATCH 46/66] added error type to validation rule. --- system/validation/rule.php | 8 ++++++++ system/validation/rules/size_of.php | 6 ++++++ system/validation/rules/upload_of.php | 19 ++++++++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/system/validation/rule.php b/system/validation/rule.php index 5eb4b4f8..fd89b5c0 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -18,6 +18,14 @@ abstract class Rule { */ public $message; + /** + * The error type. This is used for rules that have more than + * one type of error such as Size_Of and Upload_Of. + * + * @var string + */ + protected $error; + /** * Create a new validation Rule instance. * diff --git a/system/validation/rules/size_of.php b/system/validation/rules/size_of.php index 1f7e861d..e5f02b55 100644 --- a/system/validation/rules/size_of.php +++ b/system/validation/rules/size_of.php @@ -61,16 +61,19 @@ class Size_Of extends Rule { { if ( ! is_null($this->length) and $attributes[$attribute] !== $this->length) { + $this->error = 'number_wrong_size'; return false; } if ( ! is_null($this->maximum) and $attributes[$attribute] > $this->maximum) { + $this->error = 'number_too_big'; return false; } if ( ! is_null($this->minimum and $attributes[$attribute] < $this->minimum)) { + $this->error = 'number_too_small'; return false; } @@ -90,16 +93,19 @@ class Size_Of extends Rule { if ( ! is_null($this->length) and Str::length($value) !== $this->length) { + $this->error = 'string_wrong_size'; return false; } if ( ! is_null($this->maximum) and Str::length($value) > $this->maximum) { + $this->error = 'string_too_big'; return false; } if ( ! is_null($this->minimum) and Str::length($value) < $this->minimum) { + $this->error = 'string_too_small'; return false; } diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php index e45dc56d..473b9b49 100644 --- a/system/validation/rules/upload_of.php +++ b/system/validation/rules/upload_of.php @@ -7,11 +7,11 @@ use System\Validation\Rule; class Upload_Of extends Rule { /** - * The acceptable file extensions. + * The acceptable file types. * * @var array */ - public $extensions; + public $types = array(); /** * The maximum file size in bytes. @@ -38,25 +38,30 @@ class Upload_Of extends Rule { if ( ! is_null($this->maximum) and $file['size'] > $this->maximum) { + $this->error = 'file_too_big'; return false; } - if ( ! is_null($this->extensions) and ! in_array(File::extension($file['name']), $this->extensions)) + foreach ($this->types as $type) { - return false; + if ( ! File::is($type, $file['tmp_name'])) + { + $this->error = 'file_wrong_type'; + return false; + } } return true; } /** - * Set the acceptable file extensions. + * Set the acceptable file types. * * @return Upload_Of */ - public function has_extension() + public function is() { - $this->extensions = func_get_args(); + $this->types = func_get_args(); return $this; } From d51be02dd2e1260294c9140651788774c1c0b9c9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Jun 2011 17:33:07 -0500 Subject: [PATCH 47/66] enhanced validation, added mimes config array. --- application/config/mimes.php | 97 ++++++++++++ application/lang/en/validation.php | 27 ++++ system/file.php | 115 ++------------ system/validation/message.php | 144 +++++++++++++++++ system/validation/nullable_rule.php | 94 +++++++++++ system/validation/rangable_rule.php | 145 +++++++++++++++++ system/validation/rule.php | 55 ++----- system/validation/rules/acceptance_of.php | 4 +- system/validation/rules/confirmation_of.php | 2 +- system/validation/rules/exclusion_of.php | 12 +- system/validation/rules/format_of.php | 12 +- system/validation/rules/inclusion_of.php | 12 +- system/validation/rules/length_of.php | 49 ++++++ system/validation/rules/numericality_of.php | 116 ++++++++++++++ system/validation/rules/presence_of.php | 61 ++----- system/validation/rules/size_of.php | 166 -------------------- system/validation/rules/uniqueness_of.php | 17 +- system/validation/rules/upload_of.php | 106 +++++++++++-- system/validation/rules/with_callback.php | 18 +-- 19 files changed, 841 insertions(+), 411 deletions(-) create mode 100644 application/config/mimes.php create mode 100644 application/lang/en/validation.php create mode 100644 system/validation/message.php create mode 100644 system/validation/nullable_rule.php create mode 100644 system/validation/rangable_rule.php create mode 100644 system/validation/rules/length_of.php create mode 100644 system/validation/rules/numericality_of.php delete mode 100644 system/validation/rules/size_of.php diff --git a/application/config/mimes.php b/application/config/mimes.php new file mode 100644 index 00000000..e2bd4fbb --- /dev/null +++ b/application/config/mimes.php @@ -0,0 +1,97 @@ + 'application/mac-binhex40', + 'cpt' => 'application/mac-compactpro', + 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'), + 'bin' => 'application/macbinary', + 'dms' => 'application/octet-stream', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'exe' => array('application/octet-stream', 'application/x-msdownload'), + 'class' => 'application/octet-stream', + 'psd' => 'application/x-photoshop', + 'so' => 'application/octet-stream', + 'sea' => 'application/octet-stream', + 'dll' => 'application/octet-stream', + 'oda' => 'application/oda', + 'pdf' => array('application/pdf', 'application/x-download'), + 'ai' => 'application/postscript', + 'eps' => 'application/postscript', + 'ps' => 'application/postscript', + 'smi' => 'application/smil', + 'smil' => 'application/smil', + 'mif' => 'application/vnd.mif', + 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), + 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), + 'wbxml' => 'application/wbxml', + 'wmlc' => 'application/wmlc', + 'dcr' => 'application/x-director', + 'dir' => 'application/x-director', + 'dxr' => 'application/x-director', + 'dvi' => 'application/x-dvi', + 'gtar' => 'application/x-gtar', + 'gz' => 'application/x-gzip', + 'php' => array('application/x-httpd-php', 'text/x-php'), + 'php4' => 'application/x-httpd-php', + 'php3' => 'application/x-httpd-php', + 'phtml' => 'application/x-httpd-php', + 'phps' => 'application/x-httpd-php-source', + 'js' => 'application/x-javascript', + 'swf' => 'application/x-shockwave-flash', + 'sit' => 'application/x-stuffit', + 'tar' => 'application/x-tar', + 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), + 'xhtml' => 'application/xhtml+xml', + 'xht' => 'application/xhtml+xml', + 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), + 'mid' => 'audio/midi', + 'midi' => 'audio/midi', + 'mpga' => 'audio/mpeg', + 'mp2' => 'audio/mpeg', + 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), + 'aif' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', + 'aifc' => 'audio/x-aiff', + 'ram' => 'audio/x-pn-realaudio', + 'rm' => 'audio/x-pn-realaudio', + 'rpm' => 'audio/x-pn-realaudio-plugin', + 'ra' => 'audio/x-realaudio', + 'rv' => 'video/vnd.rn-realvideo', + 'wav' => 'audio/x-wav', + 'bmp' => 'image/bmp', + 'gif' => 'image/gif', + 'jpeg' => array('image/jpeg', 'image/pjpeg'), + 'jpg' => array('image/jpeg', 'image/pjpeg'), + 'jpe' => array('image/jpeg', 'image/pjpeg'), + 'png' => 'image/png', + 'tiff' => 'image/tiff', + 'tif' => 'image/tiff', + 'css' => 'text/css', + 'html' => 'text/html', + 'htm' => 'text/html', + 'shtml' => 'text/html', + 'txt' => 'text/plain', + 'text' => 'text/plain', + 'log' => array('text/plain', 'text/x-log'), + 'rtx' => 'text/richtext', + 'rtf' => 'text/rtf', + 'xml' => 'text/xml', + 'xsl' => 'text/xml', + 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', + 'mpe' => 'video/mpeg', + 'qt' => 'video/quicktime', + 'mov' => 'video/quicktime', + 'avi' => 'video/x-msvideo', + 'movie' => 'video/x-sgi-movie', + 'doc' => 'application/msword', + 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'word' => array('application/msword', 'application/octet-stream'), + 'xl' => 'application/excel', + 'eml' => 'message/rfc822', + 'json' => array('application/json', 'text/json'), + +); \ No newline at end of file diff --git a/application/lang/en/validation.php b/application/lang/en/validation.php new file mode 100644 index 00000000..8f38c22f --- /dev/null +++ b/application/lang/en/validation.php @@ -0,0 +1,27 @@ + "The :attribute must be accepted.", + "confirmation_of" => "The :attribute confirmation does not match.", + "exclusion_of" => "The :attribute value is invalid.", + "format_of" => "The :attribute format is invalid.", + "inclusion_of" => "The :attribute value is invalid.", + "presence_of" => "The :attribute can't be blank.", + "uniqueness_of" => "The :attribute has already been taken.", + "with_callback" => "The :attribute is invalid.", + + "number_not_valid" => "The :attribute is not a valid number.", + "number_not_integer" => "The :attribute is not a valid integer.", + "number_wrong_size" => "The :attribute must be :size.", + "number_too_big" => "The :attribute must be less than :max.", + "number_too_small" => "The :attribute must be at least :min.", + + "string_wrong_size" => "The :attribute must be :size characters.", + "string_too_big" => "The :attribute must be less than :max characters.", + "string_too_small" => "The :attribute must be at least :min characters.", + + "file_too_big" => "The :attribute exceeded size limit of :maxkb.", + "file_wrong_type" => "The :attribute is an invalid type.", + +); \ No newline at end of file diff --git a/system/file.php b/system/file.php index 24402dc4..7156243b 100644 --- a/system/file.php +++ b/system/file.php @@ -2,105 +2,6 @@ class File { - /** - * Extensions and their matching MIME types. - * - * @var array - */ - public static $mimes = array( - 'hqx' => 'application/mac-binhex40', - 'cpt' => 'application/mac-compactpro', - 'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream'), - 'bin' => 'application/macbinary', - 'dms' => 'application/octet-stream', - 'lha' => 'application/octet-stream', - 'lzh' => 'application/octet-stream', - 'exe' => array('application/octet-stream', 'application/x-msdownload'), - 'class' => 'application/octet-stream', - 'psd' => 'application/x-photoshop', - 'so' => 'application/octet-stream', - 'sea' => 'application/octet-stream', - 'dll' => 'application/octet-stream', - 'oda' => 'application/oda', - 'pdf' => array('application/pdf', 'application/x-download'), - 'ai' => 'application/postscript', - 'eps' => 'application/postscript', - 'ps' => 'application/postscript', - 'smi' => 'application/smil', - 'smil' => 'application/smil', - 'mif' => 'application/vnd.mif', - 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), - 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), - 'wbxml' => 'application/wbxml', - 'wmlc' => 'application/wmlc', - 'dcr' => 'application/x-director', - 'dir' => 'application/x-director', - 'dxr' => 'application/x-director', - 'dvi' => 'application/x-dvi', - 'gtar' => 'application/x-gtar', - 'gz' => 'application/x-gzip', - 'php' => array('application/x-httpd-php', 'text/x-php'), - 'php4' => 'application/x-httpd-php', - 'php3' => 'application/x-httpd-php', - 'phtml' => 'application/x-httpd-php', - 'phps' => 'application/x-httpd-php-source', - 'js' => 'application/x-javascript', - 'swf' => 'application/x-shockwave-flash', - 'sit' => 'application/x-stuffit', - 'tar' => 'application/x-tar', - 'tgz' => array('application/x-tar', 'application/x-gzip-compressed'), - 'xhtml' => 'application/xhtml+xml', - 'xht' => 'application/xhtml+xml', - 'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed'), - 'mid' => 'audio/midi', - 'midi' => 'audio/midi', - 'mpga' => 'audio/mpeg', - 'mp2' => 'audio/mpeg', - 'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'), - 'aif' => 'audio/x-aiff', - 'aiff' => 'audio/x-aiff', - 'aifc' => 'audio/x-aiff', - 'ram' => 'audio/x-pn-realaudio', - 'rm' => 'audio/x-pn-realaudio', - 'rpm' => 'audio/x-pn-realaudio-plugin', - 'ra' => 'audio/x-realaudio', - 'rv' => 'video/vnd.rn-realvideo', - 'wav' => 'audio/x-wav', - 'bmp' => 'image/bmp', - 'gif' => 'image/gif', - 'jpeg' => array('image/jpeg', 'image/pjpeg'), - 'jpg' => array('image/jpeg', 'image/pjpeg'), - 'jpe' => array('image/jpeg', 'image/pjpeg'), - 'png' => 'image/png', - 'tiff' => 'image/tiff', - 'tif' => 'image/tiff', - 'css' => 'text/css', - 'html' => 'text/html', - 'htm' => 'text/html', - 'shtml' => 'text/html', - 'txt' => 'text/plain', - 'text' => 'text/plain', - 'log' => array('text/plain', 'text/x-log'), - 'rtx' => 'text/richtext', - 'rtf' => 'text/rtf', - 'xml' => 'text/xml', - 'xsl' => 'text/xml', - 'mpeg' => 'video/mpeg', - 'mpg' => 'video/mpeg', - 'mpe' => 'video/mpeg', - 'qt' => 'video/quicktime', - 'mov' => 'video/quicktime', - 'avi' => 'video/x-msvideo', - 'movie' => 'video/x-sgi-movie', - 'doc' => 'application/msword', - 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'word' => array('application/msword', 'application/octet-stream'), - 'xl' => 'application/excel', - 'eml' => 'message/rfc822', - 'json' => array('application/json', 'text/json'), - ); - /** * Get the contents of a file. * @@ -156,9 +57,11 @@ class File { */ public static function mime($extension, $default = 'application/octet-stream') { - if (array_key_exists($extension, static::$mimes)) + $mimes = Config::get('mimes'); + + if (array_key_exists($extension, $mimes)) { - return (is_array(static::$mimes[$extension])) ? static::$mimes[$extension][0] : static::$mimes[$extension]; + return (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } return $default; @@ -167,20 +70,22 @@ class File { /** * Determine if a file is a given type. * - * The Fileinfo PHP extension will be used to determine the MIME - * type of the file. Any extension in the File::$mimes array may + * The Fileinfo PHP extension will be used to determine the MIME type + * of the file. Any extension in the mimes configuration array may * be passed as a type. */ public static function is($extension, $path) { - if ( ! array_key_exists($extension, static::$mimes)) + $mimes = Config::get('mimes'); + + if ( ! array_key_exists($extension, $mimes)) { throw new \Exception("File extension [$extension] is unknown. Cannot determine file type."); } $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); - return (is_array(static::$mimes[$extension])) ? in_array($mime, static::$mimes[$extension]) : $mime === static::$mimes[$extension]; + return (is_array($mimes[$extension])) ? in_array($mime, $mimes[$extension]) : $mime === $mimes[$extension]; } /** diff --git a/system/validation/message.php b/system/validation/message.php new file mode 100644 index 00000000..669656ae --- /dev/null +++ b/system/validation/message.php @@ -0,0 +1,144 @@ +error)) + { + $class = explode('\\', get_class($rule)); + + $rule->error = Str::lower(end($class)); + } + + return (is_null($rule->message)) ? Lang::line('validation.'.$rule->error)->get() : $rule->message; + } + + /** + * Get the error message for a Rangable rule. + * + * @param Rule $rule + * @return string + */ + private static function get_rangable_message($rule) + { + // --------------------------------------------------------- + // Rangable rules sometimes set a "presence_of" error. + // + // This occurs when an attribute is null and the option to + // allow null values has not been set. + // --------------------------------------------------------- + if ($rule->error == 'presence_of') + { + return static::get_message($rule); + } + + // --------------------------------------------------------- + // Slice "number_" or "string_" off of the error type. + // --------------------------------------------------------- + $error_type = substr($rule->error, 7); + + return (is_null($rule->$error_type)) ? Lang::line('validation.'.$rule->error)->get() : $rule->$error_type; + } + + /** + * Get the error message for an Upload_Of rule. + * + * @param Rule $rule + * @return string + */ + private static function get_upload_of_message($rule) + { + // --------------------------------------------------------- + // Slice "file_" off of the error type. + // --------------------------------------------------------- + $error_type = substr($rule->error, 5); + + return (is_null($rule->$error_type)) ? Lang::line('validation.'.$rule->error)->get() : $rule->$error_type; + } + + /** + * Prepare an error message for display. All place-holders will be replaced + * with their actual values. + * + * @param Rule $rule + * @param string $attribute + * @param string $message + * @return string + */ + private static function prepare($rule, $attribute, $message) + { + // --------------------------------------------------------- + // The rangable rule messages have three place-holders that + // must be replaced. + // + // :max = The maximum size of the attribute. + // :min = The minimum size of the attribute. + // :size = The exact size the attribute must be. + // --------------------------------------------------------- + if ($rule instanceof Rangable_Rule) + { + $message = str_replace(':max', $rule->maximum, $message); + $message = str_replace(':min', $rule->minimum, $message); + $message = str_replace(':size', $rule->size, $message); + } + // --------------------------------------------------------- + // The Upload_Of rule message have two place-holders taht + // must be replaced. + // + // :max = The maximum file size of the upload (kilobytes). + // :types = The allowed file types for the upload. + // --------------------------------------------------------- + elseif ($rule instanceof Rules\Upload_Of) + { + $message = str_replace(':max', $rule->maximum, $message); + + if (is_array($rule->types)) + { + $message = str_replace(':types', implode(', ', $rule->types), $message); + } + } + + return str_replace(':attribute', Lang::line('attributes.'.$attribute)->get(str_replace('_', ' ', $attribute)), $message); + } + +} \ No newline at end of file diff --git a/system/validation/nullable_rule.php b/system/validation/nullable_rule.php new file mode 100644 index 00000000..40f43f6e --- /dev/null +++ b/system/validation/nullable_rule.php @@ -0,0 +1,94 @@ +allow_null) + { + $this->error = 'presence_of'; + } + + return is_null($this->error); + } + + // ------------------------------------------------------------- + // Make sure the attribute is not an empty string. An error + // will be raised if the attribute is empty and empty strings + // are not allowed, halting the child's validation. + // ------------------------------------------------------------- + elseif (Str::length((string) $attributes[$attribute]) == 0 and ! $this->allow_empty) + { + $this->error = 'presence_of'; + + return false; + } + } + + /** + * Allow a empty and null to be considered valid. + * + * @return Nullable_Rule + */ + public function not_required() + { + return $this->allow_empty()->allow_null(); + } + + /** + * Allow empty to be considered valid. + * + * @return Nullable_Rule + */ + public function allow_empty() + { + $this->allow_empty = true; + return $this; + } + + /** + * Allow null to be considered valid. + * + * @return Nullable_Rule + */ + public function allow_null() + { + $this->allow_null = true; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rangable_rule.php b/system/validation/rangable_rule.php new file mode 100644 index 00000000..1845ca29 --- /dev/null +++ b/system/validation/rangable_rule.php @@ -0,0 +1,145 @@ +size = $size; + return $this; + } + + /** + * Set the minimum and maximum size of the attribute. + * + * @param int $minimum + * @param int $maximum + * @return Rangable_Rule + */ + public function between($minimum, $maximum) + { + $this->minimum = $minimum; + $this->maximum = $maximum; + + return $this; + } + + /** + * Set the minimum size the attribute. + * + * @param int $minimum + * @return Rangable_Rule + */ + public function minimum($minimum) + { + $this->minimum = $minimum; + return $this; + } + + /** + * Set the maximum size the attribute. + * + * @param int $maximum + * @return Rangable_Rule + */ + public function maximum($maximum) + { + $this->maximum = $maximum; + return $this; + } + + /** + * Set the validation error message. + * + * @param string $message + * @return Rangable_Rule + */ + public function message($message) + { + return $this->wrong_size($message)->too_big($message)->too_small($message); + } + + /** + * Set the "wrong size" error message. + * + * @param string $message + * @return Rangable_Rule + */ + public function wrong_size($message) + { + $this->wrong_size = $message; + return $this; + } + + /** + * Set the "too big" error message. + * + * @param string $message + * @return Rangable_Rule + */ + public function too_big($message) + { + $this->too_big = $message; + return $this; + } + + /** + * Set the "too small" error message. + * + * @param string $message + * @return Rangable_Rule + */ + public function too_small($message) + { + $this->too_small = $message; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rule.php b/system/validation/rule.php index fd89b5c0..2087bdf7 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -24,7 +24,7 @@ abstract class Rule { * * @var string */ - protected $error; + public $error; /** * Create a new validation Rule instance. @@ -48,50 +48,27 @@ abstract class Rule { { foreach ($this->attributes as $attribute) { + $this->error = null; + if ( ! $this->check($attribute, $attributes)) { - $errors[$attribute][] = $this->prepare_message($attribute); + $message = Message::get($this, $attribute); + + // ------------------------------------------------------------- + // Make sure the error message is not duplicated. + // + // For example, the Nullable rules can add a "required" message. + // If the same message has already been added we don't want to + // add it again. + // ------------------------------------------------------------- + if ( ! array_key_exists($attribute, $errors) or ! is_array($errors[$attribute]) or ! in_array($message, $errors[$attribute])) + { + $errors[$attribute][] = $message; + } } } } - /** - * Prepare the message to be added to the error collector. - * - * @param string $attribute - * @return string - */ - private function prepare_message($attribute) - { - if (is_null($this->message)) - { - throw new \Exception("An error message must be specified for every validation rule."); - } - - $message = $this->message; - - // --------------------------------------------------------- - // Replace any place-holders with their actual values. - // - // Attribute place-holders are loaded from the language - // directory. If the line doesn't exist, the attribute - // name will be used instead. - // --------------------------------------------------------- - if (strpos($message, ':attribute')) - { - $message = str_replace(':attribute', Lang::line('attributes.'.$attribute)->get($attribute), $message); - } - - if ($this instanceof Rules\Size_Of) - { - $message = str_replace(':max', $this->maximum, $message); - $message = str_replace(':min', $this->minimum, $message); - $message = str_replace(':size', $this->length, $message); - } - - return $message; - } - /** * Set the validation error message. * diff --git a/system/validation/rules/acceptance_of.php b/system/validation/rules/acceptance_of.php index 001c9a30..02b505a9 100644 --- a/system/validation/rules/acceptance_of.php +++ b/system/validation/rules/acceptance_of.php @@ -17,7 +17,7 @@ class Acceptance_Of extends Rule { * * @param string $attribute * @param array $attributes - * @return void + * @return bool */ public function check($attribute, $attributes) { @@ -27,7 +27,7 @@ class Acceptance_Of extends Rule { /** * Set the accepted value. * - * @param string $value + * @param string $value * @return Acceptance_Of */ public function accepts($value) diff --git a/system/validation/rules/confirmation_of.php b/system/validation/rules/confirmation_of.php index 02185cca..a6d7de0e 100644 --- a/system/validation/rules/confirmation_of.php +++ b/system/validation/rules/confirmation_of.php @@ -10,7 +10,7 @@ class Confirmation_Of extends Rule { * * @param string $attribute * @param array $attributes - * @return void + * @return bool */ public function check($attribute, $attributes) { diff --git a/system/validation/rules/exclusion_of.php b/system/validation/rules/exclusion_of.php index df0f6318..46b5a6eb 100644 --- a/system/validation/rules/exclusion_of.php +++ b/system/validation/rules/exclusion_of.php @@ -1,8 +1,8 @@ reserved); @@ -31,7 +31,7 @@ class Exclusion_Of extends Rule { /** * Set the reserved values for the attribute * - * @param array $reserved + * @param array $reserved * @return Exclusion_Of */ public function from($reserved) diff --git a/system/validation/rules/format_of.php b/system/validation/rules/format_of.php index 4b969dc0..dfcebb16 100644 --- a/system/validation/rules/format_of.php +++ b/system/validation/rules/format_of.php @@ -1,8 +1,8 @@ expression, $attributes[$attribute]); @@ -31,7 +31,7 @@ class Format_Of extends Rule { /** * Set the regular expression. * - * @param string $expression + * @param string $expression * @return Format_Of */ public function using($expression) diff --git a/system/validation/rules/inclusion_of.php b/system/validation/rules/inclusion_of.php index db1e0afb..f92ace6f 100644 --- a/system/validation/rules/inclusion_of.php +++ b/system/validation/rules/inclusion_of.php @@ -1,8 +1,8 @@ accepted); @@ -31,7 +31,7 @@ class Inclusion_Of extends Rule { /** * Set the accepted values for the attribute. * - * @param array $accepted + * @param array $accepted * @return Inclusion_Of */ public function in($accepted) diff --git a/system/validation/rules/length_of.php b/system/validation/rules/length_of.php new file mode 100644 index 00000000..f53ff5aa --- /dev/null +++ b/system/validation/rules/length_of.php @@ -0,0 +1,49 @@ +size) and Str::length($value) !== $this->size) + { + $this->error = 'string_wrong_size'; + } + // --------------------------------------------------------- + // Validate the maximum length of the attribute. + // --------------------------------------------------------- + elseif ( ! is_null($this->maximum) and Str::length($value) > $this->maximum) + { + $this->error = 'string_too_big'; + } + // --------------------------------------------------------- + // Validate the minimum length of the attribute. + // --------------------------------------------------------- + elseif ( ! is_null($this->minimum) and Str::length($value) < $this->minimum) + { + $this->error = 'string_too_small'; + } + + return is_null($this->error); + } + +} \ No newline at end of file diff --git a/system/validation/rules/numericality_of.php b/system/validation/rules/numericality_of.php new file mode 100644 index 00000000..43813ba7 --- /dev/null +++ b/system/validation/rules/numericality_of.php @@ -0,0 +1,116 @@ +error = 'number_not_valid'; + } + // --------------------------------------------------------- + // Validate the attribute is an integer. + // --------------------------------------------------------- + elseif ($this->only_integer and filter_var($attributes[$attribute], FILTER_VALIDATE_INT) === false) + { + $this->error = 'number_not_integer'; + } + // --------------------------------------------------------- + // Validate the exact size of the attribute. + // --------------------------------------------------------- + elseif ( ! is_null($this->size) and $attributes[$attribute] != $this->size) + { + $this->error = 'number_wrong_size'; + } + // --------------------------------------------------------- + // Validate the maximum size of the attribute. + // --------------------------------------------------------- + elseif ( ! is_null($this->maximum) and $attributes[$attribute] > $this->maximum) + { + $this->error = 'number_too_big'; + } + // --------------------------------------------------------- + // Validate the minimum size of the attribute. + // --------------------------------------------------------- + elseif ( ! is_null($this->minimum) and $attributes[$attribute] < $this->minimum) + { + $this->error = 'number_too_small'; + } + + return is_null($this->error); + } + + /** + * Specify that the attribute must be an integer. + * + * @return Numericality_Of + */ + public function only_integer() + { + $this->only_integer = true; + return $this; + } + + /** + * Set the "not valid" error message. + * + * @param string $message + * @return Numericality_Of + */ + public function not_valid($message) + { + $this->not_valid = $message; + return $this; + } + + /** + * Set the "not integer" error message. + * + * @param string $message + * @return Numericality_Of + */ + public function not_integer($message) + { + $this->not_integer = $message; + return $this; + } + +} \ No newline at end of file diff --git a/system/validation/rules/presence_of.php b/system/validation/rules/presence_of.php index 093b30c0..8926e967 100644 --- a/system/validation/rules/presence_of.php +++ b/system/validation/rules/presence_of.php @@ -1,70 +1,29 @@ allow_null) - { - return false; - } - - if (trim((string) $attributes[$attribute]) === '' and ! $this->allow_empty) - { - return false; + return $nullable; } + // --------------------------------------------------------- + // The Nullable_Rule check method essentially is a check for + // the presence of an attribute, so there is no further + // checking that needs to be done. + // --------------------------------------------------------- return true; } - /** - * Allow an empty string to be considered present. - * - * @return Presence_Of - */ - public function allow_empty() - { - $this->allow_empty = true; - return $this; - } - - /** - * Allow a null to be considered present. - * - * @return Presence_Of - */ - public function allow_null() - { - $this->allow_null = true; - return $this; - } - } \ No newline at end of file diff --git a/system/validation/rules/size_of.php b/system/validation/rules/size_of.php deleted file mode 100644 index e5f02b55..00000000 --- a/system/validation/rules/size_of.php +++ /dev/null @@ -1,166 +0,0 @@ -check_number($attribute, $attributes); - } - else - { - return $this->check_string($attribute, $attributes); - } - } - - /** - * Evaluate the validity of a numeric attribute. - * - * @param string $attribute - * @param array $attributes - * @return void - */ - private function check_number($attribute, $attributes) - { - if ( ! is_null($this->length) and $attributes[$attribute] !== $this->length) - { - $this->error = 'number_wrong_size'; - return false; - } - - if ( ! is_null($this->maximum) and $attributes[$attribute] > $this->maximum) - { - $this->error = 'number_too_big'; - return false; - } - - if ( ! is_null($this->minimum and $attributes[$attribute] < $this->minimum)) - { - $this->error = 'number_too_small'; - return false; - } - - return true; - } - - /** - * Evaluate the validity of a string attribute. - * - * @param string $attribute - * @param array $attributes - * @return void - */ - public function check_string($attribute, $attributes) - { - $value = trim((string) $attributes[$attribute]); - - if ( ! is_null($this->length) and Str::length($value) !== $this->length) - { - $this->error = 'string_wrong_size'; - return false; - } - - if ( ! is_null($this->maximum) and Str::length($value) > $this->maximum) - { - $this->error = 'string_too_big'; - return false; - } - - if ( ! is_null($this->minimum) and Str::length($value) < $this->minimum) - { - $this->error = 'string_too_small'; - return false; - } - - return true; - } - - /** - * Set the exact size the attribute must be. - * - * @param int $length - * @return Size_Of - */ - public function is($length) - { - $this->length = $length; - return $this; - } - - /** - * Set the minimum and maximum size of the attribute. - * - * @param int $minimum - * @param int $maximum - * @return Size_Of - */ - public function between($minimum, $maximum) - { - $this->minimum = $minimum; - $this->maximum = $maximum; - - return $this; - } - - /** - * Set the minimum size the attribute. - * - * @param int $minimum - * @return Size_Of - */ - public function at_least($minimum) - { - $this->minimum = $minimum; - return $this; - } - - /** - * Set the maximum size the attribute. - * - * @param int $maximum - * @return Size_Of - */ - public function less_than($maximum) - { - $this->maximum = $maximum; - return $this; - } - -} \ No newline at end of file diff --git a/system/validation/rules/uniqueness_of.php b/system/validation/rules/uniqueness_of.php index a693d556..94f39d67 100644 --- a/system/validation/rules/uniqueness_of.php +++ b/system/validation/rules/uniqueness_of.php @@ -1,9 +1,9 @@ column)) @@ -44,8 +44,11 @@ class Uniqueness_Of extends Rule { /** * Set the database table and column. * - * @param string $table - * @param string $column + * The attribute name will be used as the column name if no other + * column name is specified. + * + * @param string $table + * @param string $column * @return Uniqueness_Of */ public function on($table, $column = null) diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php index 473b9b49..77d71bbb 100644 --- a/system/validation/rules/upload_of.php +++ b/system/validation/rules/upload_of.php @@ -2,9 +2,9 @@ use System\File; use System\Input; -use System\Validation\Rule; +use System\Validation\Nullable_Rule; -class Upload_Of extends Rule { +class Upload_Of extends Nullable_Rule { /** * The acceptable file types. @@ -20,38 +20,72 @@ class Upload_Of extends Rule { */ public $maximum; + /** + * The "wrong type" error message. + * + * @var string + */ + public $wrong_type; + + /** + * The "too big" error message. + * + * @var string + */ + public $too_big; + /** * Evaluate the validity of an attribute. * * @param string $attribute * @param array $attributes - * @return void + * @return bool */ public function check($attribute, $attributes) { + // ----------------------------------------------------- + // Check the presence of the upload. If the upload does + // not exist and the upload is required, a presence_of + // error will be raised. + // + // Otherwise no error will be raised. + // ----------------------------------------------------- if ( ! array_key_exists($attribute, Input::file())) { - return true; + if ( ! $this->allow_null) + { + $this->error = 'presence_of'; + } + + return is_null($this->error); } + // ----------------------------------------------------- + // Uploaded files are stored in the $_FILES array, so + // we use that array instead of the $attributes. + // ----------------------------------------------------- $file = Input::file($attribute); - if ( ! is_null($this->maximum) and $file['size'] > $this->maximum) + if ( ! is_null($this->maximum) and $file['size'] > $this->maximum * 1000) { $this->error = 'file_too_big'; - return false; } + // ----------------------------------------------------- + // The File::is method uses the Fileinfo PHP extension + // to determine the MIME type of the file. + // ----------------------------------------------------- foreach ($this->types as $type) { - if ( ! File::is($type, $file['tmp_name'])) + if (File::is($type, $file['tmp_name'])) { - $this->error = 'file_wrong_type'; - return false; + break; } + + $this->error = 'file_wrong_type'; } - return true; + return is_null($this->error); } /** @@ -66,15 +100,61 @@ class Upload_Of extends Rule { } /** - * Set the maximum file size in bytes. + * Require that the uploaded file is an image type. * - * @param int $maximum * @return Upload_Of */ - public function less_than($maximum) + public function is_image() + { + $this->types = array_merge($this->types, array('jpg', 'gif', 'png', 'bmp')) + return $this; + } + + /** + * Set the maximum file size in kilobytes. + * + * @param int $maximum + * @return Upload_Of + */ + public function maximum($maximum) { $this->maximum = $maximum; return $this; } + /** + * Set the validation error message. + * + * @param string $message + * @return Upload_Of + */ + public function message($message) + { + return $this->wrong_type($message)->too_big($message); + } + + /** + * Set the "wrong type" error message. + * + * @param string $message + * @return Upload_Of + */ + public function wrong_type($message) + { + $this->wrong_type = $message; + return $this; + } + + /** + * Set the "too big" error message. + * + * @param string $message + * @return Upload_Of + */ + public function too_big($message) + { + $this->too_big = $message; + return $this; + } + } \ No newline at end of file diff --git a/system/validation/rules/with_callback.php b/system/validation/rules/with_callback.php index 8630b460..ed1d2ff3 100644 --- a/system/validation/rules/with_callback.php +++ b/system/validation/rules/with_callback.php @@ -1,8 +1,8 @@ callback)) { throw new \Exception("The validation callback for the [$attribute] attribute is not callable."); } + if ( ! is_null($nullable = parent::check($attribute, $attributes))) + { + return $nullable; + } + return call_user_func($this->callback, $attributes[$attribute]); } /** * Set the validation callback. * - * @param function $callback + * @param function $callback * @return With_Callback */ public function using($callback) From 260f99739474b513b27c47d5b94f7eab1ab243ae Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Jun 2011 20:51:38 -0500 Subject: [PATCH 48/66] added comments to validation lang. --- application/lang/en/validation.php | 38 ++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/application/lang/en/validation.php b/application/lang/en/validation.php index 8f38c22f..be2aaf66 100644 --- a/application/lang/en/validation.php +++ b/application/lang/en/validation.php @@ -2,26 +2,50 @@ return array( + /* + |-------------------------------------------------------------------------- + | General Validation Messages + |-------------------------------------------------------------------------- + */ + "acceptance_of" => "The :attribute must be accepted.", "confirmation_of" => "The :attribute confirmation does not match.", "exclusion_of" => "The :attribute value is invalid.", "format_of" => "The :attribute format is invalid.", "inclusion_of" => "The :attribute value is invalid.", - "presence_of" => "The :attribute can't be blank.", + "presence_of" => "The :attribute can't be empty.", "uniqueness_of" => "The :attribute has already been taken.", "with_callback" => "The :attribute is invalid.", - "number_not_valid" => "The :attribute is not a valid number.", - "number_not_integer" => "The :attribute is not a valid integer.", + /* + |-------------------------------------------------------------------------- + | Numericality_Of Validation Messages + |-------------------------------------------------------------------------- + */ + + "number_not_valid" => "The :attribute must be a valid number.", + "number_not_integer" => "The :attribute must be an integer.", "number_wrong_size" => "The :attribute must be :size.", - "number_too_big" => "The :attribute must be less than :max.", + "number_too_big" => "The :attribute must be no more than :max.", "number_too_small" => "The :attribute must be at least :min.", + /* + |-------------------------------------------------------------------------- + | Length_Of Validation Messages + |-------------------------------------------------------------------------- + */ + "string_wrong_size" => "The :attribute must be :size characters.", - "string_too_big" => "The :attribute must be less than :max characters.", + "string_too_big" => "The :attribute must be no more than :max characters.", "string_too_small" => "The :attribute must be at least :min characters.", - "file_too_big" => "The :attribute exceeded size limit of :maxkb.", - "file_wrong_type" => "The :attribute is an invalid type.", + /* + |-------------------------------------------------------------------------- + | Upload_Of Validation Messages + |-------------------------------------------------------------------------- + */ + + "file_wrong_type" => "The :attribute is an invalid file type.", + "file_too_big" => "The :attribute exceeds size limit of :maxkb.", ); \ No newline at end of file From 2c4e8075259de224eac3c173db8588bdc030edcd Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Jun 2011 20:53:22 -0500 Subject: [PATCH 49/66] removed .gitignore from validation lang. --- application/lang/en/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 application/lang/en/.gitignore diff --git a/application/lang/en/.gitignore b/application/lang/en/.gitignore deleted file mode 100644 index e69de29b..00000000 From fef1809982e2b6fb726168f25192f9a084f44748 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 27 Jun 2011 21:08:49 -0500 Subject: [PATCH 50/66] fix syntax error in upload_of... add types to file_wrong_type lang message. --- application/lang/en/validation.php | 2 +- system/validation/rules/upload_of.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/lang/en/validation.php b/application/lang/en/validation.php index be2aaf66..67d22c34 100644 --- a/application/lang/en/validation.php +++ b/application/lang/en/validation.php @@ -45,7 +45,7 @@ return array( |-------------------------------------------------------------------------- */ - "file_wrong_type" => "The :attribute is an invalid file type.", + "file_wrong_type" => "The :attribute must be a file of type: :types.", "file_too_big" => "The :attribute exceeds size limit of :maxkb.", ); \ No newline at end of file diff --git a/system/validation/rules/upload_of.php b/system/validation/rules/upload_of.php index 77d71bbb..4dfba8ca 100644 --- a/system/validation/rules/upload_of.php +++ b/system/validation/rules/upload_of.php @@ -106,7 +106,7 @@ class Upload_Of extends Nullable_Rule { */ public function is_image() { - $this->types = array_merge($this->types, array('jpg', 'gif', 'png', 'bmp')) + $this->types = array_merge($this->types, array('jpg', 'gif', 'png', 'bmp')); return $this; } From 1aa86d0798fe08af04c283f4f627294783a44606 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 12:21:21 -0500 Subject: [PATCH 51/66] improved performance. added support for database ports. --- application/config/aliases.php | 45 ++++++++++ application/config/application.php | 42 --------- application/views/home/index.php | 114 ++++++++++++------------ public/index.php | 8 +- system/db.php | 22 ++++- system/db/connector.php | 15 +++- system/db/eloquent.php | 11 +-- system/db/query.php | 4 +- system/db/query/dynamic.php | 2 +- system/inflector.php | 4 +- system/loader.php | 6 +- system/request.php | 4 +- system/validation/error_collector.php | 123 ++++++++++++++++++++++++++ system/validation/message.php | 2 +- system/validation/rule.php | 20 +---- system/validator.php | 10 ++- 16 files changed, 288 insertions(+), 144 deletions(-) create mode 100644 application/config/aliases.php create mode 100644 system/validation/error_collector.php diff --git a/application/config/aliases.php b/application/config/aliases.php new file mode 100644 index 00000000..72a0b1bf --- /dev/null +++ b/application/config/aliases.php @@ -0,0 +1,45 @@ + 'System\\Auth', + 'Benchmark' => 'System\\Benchmark', + 'Cache' => 'System\\Cache', + 'Config' => 'System\\Config', + 'Cookie' => 'System\\Cookie', + 'Crypt' => 'System\\Crypt', + 'Date' => 'System\\Date', + 'DB' => 'System\\DB', + 'Download' => 'System\\Download', + 'Eloquent' => 'System\\DB\\Eloquent', + 'File' => 'System\\File', + 'Form' => 'System\\Form', + 'Hash' => 'System\\Hash', + 'HTML' => 'System\\HTML', + 'Inflector' => 'System\\Inflector', + 'Input' => 'System\\Input', + 'Lang' => 'System\\Lang', + 'Log' => 'System\\Log', + 'URL' => 'System\\URL', + 'Redirect' => 'System\\Redirect', + 'Request' => 'System\\Request', + 'Response' => 'System\\Response', + 'Session' => 'System\\Session', + 'Str' => 'System\\Str', + 'Text' => 'System\\Text', + 'Validator' => 'System\\Validator', + 'View' => 'System\\View', + +); \ No newline at end of file diff --git a/application/config/application.php b/application/config/application.php index 00fba80a..2f55b140 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -80,46 +80,4 @@ return array( 'key' => '', - /* - |-------------------------------------------------------------------------- - | Class Aliases - |-------------------------------------------------------------------------- - | - | Here, you can specify any class aliases that you would like registered - | when Laravel loads. Aliases are lazy-loaded, so add as many as you want. - | - | We have already setup a few to make your life easier. - | - */ - - 'aliases' => array( - 'Auth' => 'System\\Auth', - 'Benchmark' => 'System\\Benchmark', - 'Cache' => 'System\\Cache', - 'Config' => 'System\\Config', - 'Cookie' => 'System\\Cookie', - 'Crypt' => 'System\\Crypt', - 'Date' => 'System\\Date', - 'DB' => 'System\\DB', - 'Download' => 'System\\Download', - 'Eloquent' => 'System\\DB\\Eloquent', - 'File' => 'System\\File', - 'Form' => 'System\\Form', - 'Hash' => 'System\\Hash', - 'HTML' => 'System\\HTML', - 'Inflector' => 'System\\Inflector', - 'Input' => 'System\\Input', - 'Lang' => 'System\\Lang', - 'Log' => 'System\\Log', - 'URL' => 'System\\URL', - 'Redirect' => 'System\\Redirect', - 'Request' => 'System\\Request', - 'Response' => 'System\\Response', - 'Session' => 'System\\Session', - 'Str' => 'System\\Str', - 'Text' => 'System\\Text', - 'Validator' => 'System\\Validator', - 'View' => 'System\\View', - ), - ); \ No newline at end of file diff --git a/application/views/home/index.php b/application/views/home/index.php index 59b997e8..4e17bf50 100644 --- a/application/views/home/index.php +++ b/application/views/home/index.php @@ -4,74 +4,76 @@ Welcome To Laravel! - - + + + - - + +
-

Laravel

- -
- You have successfully installed Laravel. +

Installation Complete!

-

+

Ready to dig in? Start building your application in the application/routes.php file.

- Perhaps you would like to peruse the documentation or contribute on GitHub? -
- - -
+

Need to learn more? Peruse our wonderful documentation.

+ \ No newline at end of file diff --git a/public/index.php b/public/index.php index 09dc52ec..f813717e 100644 --- a/public/index.php +++ b/public/index.php @@ -29,21 +29,15 @@ define('PACKAGE_PATH', APP_PATH.'packages/'); define('EXT', '.php'); // -------------------------------------------------------------- -// Load the configuration, error, and string classes. +// Load the configuration class. // -------------------------------------------------------------- require SYS_PATH.'config'.EXT; -require SYS_PATH.'str'.EXT; // -------------------------------------------------------------- // Register the auto-loader. // -------------------------------------------------------------- spl_autoload_register(require SYS_PATH.'loader'.EXT); -// -------------------------------------------------------------- -// Set the Laravel starting time in the Benchmark class. -// -------------------------------------------------------------- -System\Benchmark::$marks['laravel'] = LARAVEL_START; - // -------------------------------------------------------------- // Set the error reporting level. // -------------------------------------------------------------- diff --git a/system/db.php b/system/db.php index fbdcaf1f..0f064ef8 100644 --- a/system/db.php +++ b/system/db.php @@ -66,11 +66,11 @@ class DB { // // For all other statements, return a boolean. // --------------------------------------------------- - if (strpos(Str::upper($sql), 'SELECT') === 0) + if (strpos(strtoupper($sql), 'SELECT') === 0) { return $query->fetchAll(\PDO::FETCH_CLASS, 'stdClass'); } - elseif (strpos(Str::upper($sql), 'UPDATE') === 0 or strpos(Str::upper($sql), 'DELETE') === 0) + elseif (strpos(strtoupper($sql), 'UPDATE') === 0 or strpos(strtoupper($sql), 'DELETE') === 0) { return $query->rowCount(); } @@ -105,4 +105,22 @@ class DB { return static::connection($connection)->getAttribute(\PDO::ATTR_DRIVER_NAME); } + /** + * Get the table prefix for a database connection. + * + * @param string $connection + * @return string + */ + public static function prefix($connection = null) + { + $connections = Config::get('db.connections'); + + if (is_null($connection)) + { + $connection = Config::get('db.default'); + } + + return (array_key_exists('prefix', $connections[$connection])) ? $connections[$connection]['prefix'] : ''; + } + } \ No newline at end of file diff --git a/system/db/connector.php b/system/db/connector.php index f494b4ed..25a50375 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -51,8 +51,21 @@ class Connector { // ----------------------------------------------------- elseif ($config->driver == 'mysql' or $config->driver == 'pgsql') { - $connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options); + // ----------------------------------------------------- + // Build the PDO connection DSN. + // ----------------------------------------------------- + $dsn = $config->driver.':host='.$config->host.';dbname='.$config->database; + if (isset($config->port)) + { + $dsn .= ';port='.$config->port; + } + + $connection = new \PDO($dsn, $config->username, $config->password, static::$options); + + // ----------------------------------------------------- + // Set the appropriate character set for the datbase. + // ----------------------------------------------------- if (isset($config->charset)) { $connection->prepare("SET NAMES '".$config->charset."'")->execute(); diff --git a/system/db/eloquent.php b/system/db/eloquent.php index a5b383c5..584a03bf 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -1,6 +1,7 @@ relating_key = (is_null($foreign_key)) ? Str::lower(get_class($this)).'_id' : $foreign_key; + $this->relating_key = (is_null($foreign_key)) ? strtolower(get_class($this)).'_id' : $foreign_key; return static::make($model)->where($this->relating_key, '=', $this->id); } @@ -276,7 +277,7 @@ abstract class Eloquent { sort($models); - $this->relating_table = Str::lower($models[0].'_'.$models[1]); + $this->relating_table = strtolower($models[0].'_'.$models[1]); } // ----------------------------------------------------- @@ -286,11 +287,11 @@ abstract class Eloquent { // // This is the same convention as has_one and has_many. // ----------------------------------------------------- - $this->relating_key = Str::lower(get_class($this)).'_id'; + $this->relating_key = strtolower(get_class($this)).'_id'; return static::make($model) ->select(static::table($model).'.*') - ->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.Str::lower($model).'_id') + ->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.strtolower($model).'_id') ->where($this->relating_table.'.'.$this->relating_key, '=', $this->id); } diff --git a/system/db/query.php b/system/db/query.php index 0d053554..85e02b2f 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -326,7 +326,7 @@ class Query { */ public function order_by($column, $direction) { - $this->orderings[] = $this->wrap($column).' '.Str::upper($direction); + $this->orderings[] = $this->wrap($column).' '.strtoupper($direction); return $this; } @@ -516,7 +516,7 @@ class Query { // --------------------------------------------------------- if (in_array($method, array('count', 'min', 'max', 'avg', 'sum'))) { - return ($method == 'count') ? $this->aggregate(Str::upper($method), '*') : $this->aggregate(Str::upper($method), $parameters[0]); + return ($method == 'count') ? $this->aggregate(strtoupper($method), '*') : $this->aggregate(strtoupper($method), $parameters[0]); } throw new \Exception("Method [$method] is not defined on the Query class."); diff --git a/system/db/query/dynamic.php b/system/db/query/dynamic.php index 5b507546..354ac57b 100644 --- a/system/db/query/dynamic.php +++ b/system/db/query/dynamic.php @@ -55,7 +55,7 @@ class Dynamic { } else { - $connector = trim(Str::upper($segment), '_'); + $connector = trim(strtoupper($segment), '_'); } } diff --git a/system/inflector.php b/system/inflector.php index 981c5a48..44e0ca61 100644 --- a/system/inflector.php +++ b/system/inflector.php @@ -126,7 +126,7 @@ class Inflector { return static::$plural_cache[$value]; } - if (in_array(Str::lower($value), static::$uncountable)) + if (in_array(strtolower($value), static::$uncountable)) { return static::$plural_cache[$value] = $value; } @@ -165,7 +165,7 @@ class Inflector { return static::$singular_cache[$value]; } - if (in_array(Str::lower($value), static::$uncountable)) + if (in_array(strtolower($value), static::$uncountable)) { return static::$singular_cache[$value] = $value; } diff --git a/system/loader.php b/system/loader.php index a9491592..86960f89 100644 --- a/system/loader.php +++ b/system/loader.php @@ -4,16 +4,16 @@ * This function is registered on the auto-loader stack by the front controller. */ return function($class) { - + // ---------------------------------------------------------- // Replace namespace slashes with directory slashes. // ---------------------------------------------------------- - $file = System\Str::lower(str_replace('\\', '/', $class)); + $file = strtolower(str_replace('\\', '/', $class)); // ---------------------------------------------------------- // Should the class be aliased? // ---------------------------------------------------------- - if (array_key_exists($class, $aliases = System\Config::get('application.aliases'))) + if (array_key_exists($class, $aliases = System\Config::get('aliases'))) { return class_alias($aliases[$class], $class); } diff --git a/system/request.php b/system/request.php index 064eef3b..e9b4d618 100644 --- a/system/request.php +++ b/system/request.php @@ -71,7 +71,7 @@ class Request { // If the requests is to the root of the application, we // always return a single forward slash. // ------------------------------------------------------- - return ($uri == '') ? '/' : Str::lower($uri); + return ($uri == '') ? '/' : strtolower($uri); } /** @@ -136,7 +136,7 @@ class Request { */ public static function is_ajax() { - return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and Str::lower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); + return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) and strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'); } /** diff --git a/system/validation/error_collector.php b/system/validation/error_collector.php new file mode 100644 index 00000000..b0bbee9b --- /dev/null +++ b/system/validation/error_collector.php @@ -0,0 +1,123 @@ +messages = $messages; + } + + /** + * Add an error message to the collector. + * + * Duplicate messages will not be added. + * + * @param string $attribute + * @param string $message + * @return void + */ + public function add($attribute, $message) + { + // ------------------------------------------------------------- + // Make sure the error message is not duplicated. + // + // For example, the Nullable rules can add a "required" message. + // If the same message has already been added we don't want to + // add it again. + // ------------------------------------------------------------- + if ( ! array_key_exists($attribute, $this->messages) or ! is_array($this->messages[$attribute]) or ! in_array($message, $this->messages[$attribute])) + { + $this->messages[$attribute][] = $message; + } + } + + /** + * Determine if errors exist for an attribute. + * + * @param string $attribute + * @return bool + */ + public function has($attribute) + { + return $this->first($attribute) !== ''; + } + + /** + * Get the first error message for an attribute. + * + * @param string $attribute + * @return string + */ + public function first($attribute) + { + return (count($messages = $this->get($attribute)) > 0) ? $messages[0] : ''; + } + + /** + * Get all of the error messages for an attribute. + * + * If no attribute is specified, all of the error messages will be returned. + * + * @param string $attribute + * @param string $format + * @return array + */ + public function get($attribute = null, $format = ':message') + { + if (is_null($attribute)) + { + return $this->all($format); + } + + return (array_key_exists($attribute, $this->messages)) ? $this->format($this->messages[$attribute], $format) : array(); + } + + /** + * Get all of the error messages. + * + * @param string $format + * @return array + */ + public function all($format = ':message') + { + $all = array(); + + // --------------------------------------------------------- + // Add each error message to the array of messages. Each + // messages will have the specified format applied to it. + // --------------------------------------------------------- + foreach ($this->messages as $messages) + { + $all = array_merge($all, $this->format($messages, $format)); + } + + return $all; + } + + /** + * Format an array of messages. + * + * @param array $messages + * @param string $format + * @return array + */ + private function format($messages, $format) + { + array_walk($messages, function(&$message, $key) use ($format) { $message = str_replace(':message', $message, $format); }); + + return $messages; + } + +} \ No newline at end of file diff --git a/system/validation/message.php b/system/validation/message.php index 669656ae..50d93746 100644 --- a/system/validation/message.php +++ b/system/validation/message.php @@ -47,7 +47,7 @@ class Message { { $class = explode('\\', get_class($rule)); - $rule->error = Str::lower(end($class)); + $rule->error = strtolower(end($class)); } return (is_null($rule->message)) ? Lang::line('validation.'.$rule->error)->get() : $rule->message; diff --git a/system/validation/rule.php b/system/validation/rule.php index 2087bdf7..fa0c6692 100644 --- a/system/validation/rule.php +++ b/system/validation/rule.php @@ -40,11 +40,11 @@ abstract class Rule { /** * Run the validation rule. * - * @param array $attributes - * @param array $errors + * @param array $attributes + * @param Error_Collector $errors * @return void */ - public function validate($attributes, &$errors) + public function validate($attributes, $errors) { foreach ($this->attributes as $attribute) { @@ -52,19 +52,7 @@ abstract class Rule { if ( ! $this->check($attribute, $attributes)) { - $message = Message::get($this, $attribute); - - // ------------------------------------------------------------- - // Make sure the error message is not duplicated. - // - // For example, the Nullable rules can add a "required" message. - // If the same message has already been added we don't want to - // add it again. - // ------------------------------------------------------------- - if ( ! array_key_exists($attribute, $errors) or ! is_array($errors[$attribute]) or ! in_array($message, $errors[$attribute])) - { - $errors[$attribute][] = $message; - } + $errors->add($attribute, Message::get($this, $attribute)); } } } diff --git a/system/validator.php b/system/validator.php index cfb2a7f4..895a22d4 100644 --- a/system/validator.php +++ b/system/validator.php @@ -10,9 +10,9 @@ class Validator { public $attributes; /** - * The validation errors + * The validation error collector. * - * @var array + * @var Error_Collector */ public $errors; @@ -31,6 +31,8 @@ class Validator { */ public function __construct($target = array()) { + $this->errors = new Validation\Error_Collector; + // --------------------------------------------------------- // If the source is an Eloquent model, use the model's // attributes as the validation attributes. @@ -56,7 +58,7 @@ class Validator { */ public function is_valid() { - $this->errors = array(); + $this->errors->messages = array(); foreach ($this->rules as $rule) { @@ -67,7 +69,7 @@ class Validator { $rule->validate($this->attributes, $this->errors); } - return count($this->errors) == 0; + return count($this->errors->messages) == 0; } /** From b7997a95ba59c42d765ba6ad0aacaeea93725759 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 13:11:41 -0700 Subject: [PATCH 52/66] Tweaked request URI determination. --- system/request.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/system/request.php b/system/request.php index e9b4d618..0252232d 100644 --- a/system/request.php +++ b/system/request.php @@ -53,7 +53,7 @@ class Request { } // ------------------------------------------------------- - // Remove the application URL. + // Remove the application URL and any extra slashes. // ------------------------------------------------------- $base_url = parse_url(Config::get('application.url'), PHP_URL_PATH); @@ -62,10 +62,17 @@ class Request { $uri = (string) substr($uri, strlen($base_url)); } + $uri = trim($uri, '/'); + // ------------------------------------------------------- - // Remove the application index and any extra slashes. + // Remove the application index. // ------------------------------------------------------- - $uri = trim(str_replace('/index.php', '', $uri), '/'); + $index = Config::get('application.index'); + + if (strpos($uri, $index) === 0) + { + $uri = (string) substr($uri, strlen($index)); + } // ------------------------------------------------------- // If the requests is to the root of the application, we From e452bbdf3a5cbf72670bd2bef2d35620c07a6444 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 15:01:15 -0700 Subject: [PATCH 53/66] Fixed return type of Eloquent delete method. --- system/db/eloquent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/db/eloquent.php b/system/db/eloquent.php index 584a03bf..9263faab 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -366,7 +366,7 @@ abstract class Eloquent { // ----------------------------------------------------- if ($this->exists) { - return Query::table(static::table(get_class($this)))->delete($this->id) == 1; + return Query::table(static::table(get_class($this)))->delete($this->id); } return $this->query->delete($id); From cd903fc0ceafa562b7496481468cb06f680be03c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 20:11:05 -0500 Subject: [PATCH 54/66] tweaked uri determination. --- system/request.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/request.php b/system/request.php index 0252232d..70986c41 100644 --- a/system/request.php +++ b/system/request.php @@ -53,7 +53,7 @@ class Request { } // ------------------------------------------------------- - // Remove the application URL and any extra slashes. + // Remove the application URL. // ------------------------------------------------------- $base_url = parse_url(Config::get('application.url'), PHP_URL_PATH); @@ -62,18 +62,18 @@ class Request { $uri = (string) substr($uri, strlen($base_url)); } - $uri = trim($uri, '/'); - // ------------------------------------------------------- - // Remove the application index. + // Remove the application index and any extra slashes. // ------------------------------------------------------- $index = Config::get('application.index'); - if (strpos($uri, $index) === 0) + if (strpos($uri, '/'.$index) === 0) { - $uri = (string) substr($uri, strlen($index)); + $uri = (string) substr($uri, strlen('/'.$index)); } + $uri = trim($uri, '/'); + // ------------------------------------------------------- // If the requests is to the root of the application, we // always return a single forward slash. From de6312ccf94a588a63a2af7b2a7c9b2584949927 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 22:47:44 -0500 Subject: [PATCH 55/66] adjusted route/loader comments. --- system/route/loader.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/system/route/loader.php b/system/route/loader.php index de694b30..d03a1d5d 100644 --- a/system/route/loader.php +++ b/system/route/loader.php @@ -25,18 +25,21 @@ class Loader { // -------------------------------------------------------------- // If the request is to the root, load the "home" routes file. + // + // Otherwise, load the route file matching the first segment of + // the URI as well as the "home" routes file. // -------------------------------------------------------------- if ($uri == '/') { return require APP_PATH.'routes/home'.EXT; } - // -------------------------------------------------------------- - // Load the route file matching the first segment of the URI. - // -------------------------------------------------------------- else { $segments = explode('/', trim($uri, '/')); + // -------------------------------------------------------------- + // If the file doesn't exist, we'll just return the "home" file. + // -------------------------------------------------------------- if ( ! file_exists(APP_PATH.'routes/'.$segments[0].EXT)) { return require APP_PATH.'routes/home'.EXT; From 4f73200675a4090223777c96a62c283b45b44471 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 28 Jun 2011 23:26:42 -0500 Subject: [PATCH 56/66] moved route filter to route directory. --- public/index.php | 4 ++-- system/route.php | 4 ++-- system/{ => route}/filter.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename system/{ => route}/filter.php (97%) diff --git a/public/index.php b/public/index.php index f813717e..6375c304 100644 --- a/public/index.php +++ b/public/index.php @@ -83,7 +83,7 @@ if (System\Config::get('session.driver') != '') // -------------------------------------------------------------- // Execute the global "before" filter. // -------------------------------------------------------------- -$response = System\Filter::call('before', array(), true); +$response = System\Route\Filter::call('before', array(), true); // -------------------------------------------------------------- // Only execute the route function if the "before" filter did @@ -116,7 +116,7 @@ else // ---------------------------------------------------------- // Execute the global "after" filter. // ---------------------------------------------------------- -System\Filter::call('after', array($response)); +System\Route\Filter::call('after', array($response)); // ---------------------------------------------------------- // Stringify the response. diff --git a/system/route.php b/system/route.php index 8210a7f3..451bf718 100644 --- a/system/route.php +++ b/system/route.php @@ -63,7 +63,7 @@ class Route { // ------------------------------------------------------------ elseif (is_array($this->callback)) { - $response = isset($this->callback['before']) ? Filter::call($this->callback['before'], array(), true) : null; + $response = isset($this->callback['before']) ? Route\Filter::call($this->callback['before'], array(), true) : null; // ------------------------------------------------------------ // We verify that the before filters did not return a response @@ -80,7 +80,7 @@ class Route { if (is_array($this->callback) and isset($this->callback['after'])) { - Filter::call($this->callback['after'], array($response)); + Route\Filter::call($this->callback['after'], array($response)); } return $response; diff --git a/system/filter.php b/system/route/filter.php similarity index 97% rename from system/filter.php rename to system/route/filter.php index e3ca5500..6b1c59f7 100644 --- a/system/filter.php +++ b/system/route/filter.php @@ -1,4 +1,4 @@ - Date: Wed, 29 Jun 2011 14:19:06 -0700 Subject: [PATCH 57/66] Fixing tabbing on HTML::entities method. --- system/html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/html.php b/system/html.php index 604a9ed2..f92a0e6a 100644 --- a/system/html.php +++ b/system/html.php @@ -10,7 +10,7 @@ class HTML { */ public static function entities($value) { - return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false); + return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false); } /** From 6af79d8bdb2e639bc2a9c960c06b1b5c913d284f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 07:31:57 -0700 Subject: [PATCH 58/66] Added ability to dynamically create links to named routes using the HTML class. --- system/html.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/system/html.php b/system/html.php index f92a0e6a..89968130 100644 --- a/system/html.php +++ b/system/html.php @@ -76,6 +76,34 @@ class HTML { return static::link($url, $title, $attributes, false, true); } + /** + * Generate an HTML link to a route. + * + * @param string $name + * @param string $title + * @param array $parameters + * @param array $attributes + * @return string + */ + public static function link_to_route($name, $title, $parameters = array(), $attributes = array(), $https = false) + { + return static::link(URL::to_route($name, $parameters, $https), $title, $attributes); + } + + /** + * Generate an HTTPS HTML link to a route. + * + * @param string $name + * @param string $title + * @param array $parameters + * @param array $attributes + * @return string + */ + public static function link_to_secure_route($name, $title, $parameters = array(), $attributes = array()) + { + return static::link_to_route($name, $title, $parameters, $attributes, true); + } + /** * Generate an HTML mailto link. * @@ -250,4 +278,28 @@ class HTML { return $safe; } + /** + * Magic Method for handling dynamic static methods. + */ + public static function __callStatic($method, $parameters) + { + // ------------------------------------------------------- + // Handle the dynamic creation of links to secure routes. + // ------------------------------------------------------- + if (strpos($method, 'link_to_secure_') === 0) + { + array_unshift($parameters, substr($method, 15)); + return forward_static_call_array('HTML::link_to_secure_route', $parameters); + } + + // ------------------------------------------------------- + // Handle the dynamic creation of links to routes. + // ------------------------------------------------------- + if (strpos($method, 'link_to_') === 0) + { + array_unshift($parameters, substr($method, 8)); + return forward_static_call_array('HTML::link_to_route', $parameters); + } + } + } \ No newline at end of file From 553f377ed0f1981cfd3735de1020d164e3c60914 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 07:39:27 -0700 Subject: [PATCH 59/66] Adjusted signature for dynamic route URL creation. --- system/url.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/url.php b/system/url.php index b048dd7d..4bc7d10c 100644 --- a/system/url.php +++ b/system/url.php @@ -147,6 +147,7 @@ class URL { // ---------------------------------------------------- if (strpos($method, 'to_secure_') === 0) { + $parameters = (isset($parameters[0])) ? $parameters[0] : array(); return static::to_route(substr($method, 10), $parameters, true); } @@ -155,6 +156,7 @@ class URL { // ---------------------------------------------------- if (strpos($method, 'to_') === 0) { + $parameters = (isset($parameters[0])) ? $parameters[0] : array(); return static::to_route(substr($method, 3), $parameters); } From c7e7d64545a7739af4bcd252d2b82ba51463060f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 07:45:05 -0700 Subject: [PATCH 60/66] Refactoring dynamic URLs to routes. --- system/url.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/url.php b/system/url.php index 4bc7d10c..dfcd8208 100644 --- a/system/url.php +++ b/system/url.php @@ -142,12 +142,13 @@ class URL { */ public static function __callStatic($method, $parameters) { + $parameters = (isset($parameters[0])) ? $parameters[0] : array(); + // ---------------------------------------------------- // Dynamically create a secure route URL. // ---------------------------------------------------- if (strpos($method, 'to_secure_') === 0) { - $parameters = (isset($parameters[0])) ? $parameters[0] : array(); return static::to_route(substr($method, 10), $parameters, true); } @@ -156,7 +157,6 @@ class URL { // ---------------------------------------------------- if (strpos($method, 'to_') === 0) { - $parameters = (isset($parameters[0])) ? $parameters[0] : array(); return static::to_route(substr($method, 3), $parameters); } From 87ec697f2d70f56bbf0b7c82fb43a4e56fedfec3 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 07:45:38 -0700 Subject: [PATCH 61/66] Refactoring dynamic redirects to routes. --- system/redirect.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/redirect.php b/system/redirect.php index 51662493..70d764bb 100644 --- a/system/redirect.php +++ b/system/redirect.php @@ -77,6 +77,8 @@ class Redirect { */ public static function __callStatic($method, $parameters) { + $parameters = (isset($parameters[0])) ? $parameters[0] : array(); + // ---------------------------------------------------- // Dynamically redirect to a secure route URL. // ---------------------------------------------------- From 8d3998035f770fb2bc46499cf1fe4363dd63bb65 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 08:23:49 -0700 Subject: [PATCH 62/66] Improved readme.md. --- readme.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index d3405c9c..d40c5b2e 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,28 @@ -# Laravel - A Clean & Classy PHP Framework +## Laravel - A Clean & Classy PHP Framework -## For more information, visit [http://laravel.com](http://laravel.com/ "Laravel") +### For more information, visit [http://laravel.com](http://laravel.com) + +### For complete documentation, visit [http://docs.laravel.com](http://docs.laravel.com) + +Laravel is a clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. Enjoy the fresh air. + +#### Simple, Expressive Syntax + +Stay true to the web with RESTful routing: + + 'GET /' => function() + { + return View::make('home/index'); + } + +Redirect to a named route and flash something to the session: + + return Redirect::to_profile()->with('message', 'Welcome Back!'); + +Retrieve recent blog posts and eagerly load the comments using Eloquent ORM: + + $posts = Post::with('comments')->order_by('created_at', 'desc')->take(10)->get(); + +Get input from the previous request to re-populate a form: + + echo Input::old('email'); \ No newline at end of file From d0a716b8105dcdd0c17e0cc7a431355d688ad788 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 08:24:42 -0700 Subject: [PATCH 63/66] Edited readme.md. --- readme.md | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/readme.md b/readme.md index d40c5b2e..30adf4bc 100644 --- a/readme.md +++ b/readme.md @@ -1,28 +1,5 @@ -## Laravel - A Clean & Classy PHP Framework +# Laravel - A Clean & Classy PHP Framework ### For more information, visit [http://laravel.com](http://laravel.com) -### For complete documentation, visit [http://docs.laravel.com](http://docs.laravel.com) - -Laravel is a clean and classy framework for PHP web development. Freeing you from spaghetti code, Laravel helps you create wonderful applications using simple, expressive syntax. Development should be a creative experience that you enjoy, not something that is painful. Enjoy the fresh air. - -#### Simple, Expressive Syntax - -Stay true to the web with RESTful routing: - - 'GET /' => function() - { - return View::make('home/index'); - } - -Redirect to a named route and flash something to the session: - - return Redirect::to_profile()->with('message', 'Welcome Back!'); - -Retrieve recent blog posts and eagerly load the comments using Eloquent ORM: - - $posts = Post::with('comments')->order_by('created_at', 'desc')->take(10)->get(); - -Get input from the previous request to re-populate a form: - - echo Input::old('email'); \ No newline at end of file +### For complete documentation, visit [http://docs.laravel.com](http://docs.laravel.com) \ No newline at end of file From 4d98a5e409a93d28be6eff24518316f17d6b40b2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 08:26:14 -0700 Subject: [PATCH 64/66] Incremented version number. --- public/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/index.php b/public/index.php index 6375c304..7ecf345f 100644 --- a/public/index.php +++ b/public/index.php @@ -3,7 +3,7 @@ * Laravel - A clean and classy framework for PHP web development. * * @package Laravel - * @version 1.0.0 Beta 2 + * @version 1.1.0 * @author Taylor Otwell * @license MIT License * @link http://laravel.com From e2f382545b8f2e824ffe13a9923c93a4062d0333 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 09:24:19 -0700 Subject: [PATCH 65/66] Removed Download class from aliases configuration. --- application/config/aliases.php | 1 - 1 file changed, 1 deletion(-) diff --git a/application/config/aliases.php b/application/config/aliases.php index 72a0b1bf..d7d3f4b6 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -22,7 +22,6 @@ return array( 'Crypt' => 'System\\Crypt', 'Date' => 'System\\Date', 'DB' => 'System\\DB', - 'Download' => 'System\\Download', 'Eloquent' => 'System\\DB\\Eloquent', 'File' => 'System\\File', 'Form' => 'System\\Form', From 21f33bb46d1d90b6b1521749a5a274f1dc6b472a Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 30 Jun 2011 09:41:58 -0700 Subject: [PATCH 66/66] Tweaking built-in validation messages. --- application/lang/en/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/lang/en/validation.php b/application/lang/en/validation.php index 67d22c34..fa09a0be 100644 --- a/application/lang/en/validation.php +++ b/application/lang/en/validation.php @@ -23,7 +23,7 @@ return array( |-------------------------------------------------------------------------- */ - "number_not_valid" => "The :attribute must be a valid number.", + "number_not_valid" => "The :attribute must be a number.", "number_not_integer" => "The :attribute must be an integer.", "number_wrong_size" => "The :attribute must be :size.", "number_too_big" => "The :attribute must be no more than :max.",