From f7bb0c551068a615158571490ac372938fd6e2b0 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 10 Jun 2011 12:43:09 -0500 Subject: [PATCH] trimmed comment bloat. returning boolean on eloquent save. --- application/config/application.php | 1 + system/auth.php | 22 -------- system/cache/driver/file.php | 9 +--- system/config.php | 36 -------------- system/cookie.php | 3 -- system/crypt.php | 19 ------- system/db.php | 15 ------ system/db/connector.php | 6 --- system/db/eloquent.php | 46 +++-------------- system/db/eloquent/factory.php | 5 +- system/db/eloquent/hydrate.php | 40 +-------------- system/db/eloquent/relate.php | 47 ------------------ system/db/eloquent/warehouse.php | 18 ++----- system/db/query.php | 68 ++----------------------- system/db/query/compiler.php | 26 +--------- system/download.php | 6 --- system/error.php | 21 -------- system/filter.php | 9 +--- system/form.php | 55 -------------------- system/hash.php | 7 --- system/html.php | 38 ++------------ system/inflector.php | 6 --- system/input.php | 12 +---- system/lang.php | 26 +--------- system/loader.php | 12 ----- system/log.php | 14 ------ system/memcached.php | 6 --- system/redirect.php | 6 --- system/request.php | 12 ----- system/response.php | 9 ---- system/route.php | 3 -- system/router.php | 31 +----------- system/session.php | 36 ++------------ system/session/driver/db.php | 13 ----- system/session/driver/file.php | 6 --- system/str.php | 9 ---- system/test.php | 65 ++++++++++++++++++++++++ system/tests/.gitignore | 0 system/text.php | 30 ----------- system/url.php | 6 --- system/view.php | 28 ----------- system/views/error/exception.php | 1 + system/views/test/report.php | 80 ++++++++++++++++++++++++++++++ 43 files changed, 178 insertions(+), 730 deletions(-) create mode 100644 system/test.php create mode 100644 system/tests/.gitignore create mode 100644 system/views/test/report.php diff --git a/application/config/application.php b/application/config/application.php index efe0b20a..49fb77da 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -92,6 +92,7 @@ 'Response' => 'System\\Response', 'Session' => 'System\\Session', 'Str' => 'System\\Str', + 'Test' => 'System\\Test', 'Text' => 'System\\Text', 'View' => 'System\View', ), diff --git a/system/auth.php b/system/auth.php index 198c32bd..00bb3e11 100644 --- a/system/auth.php +++ b/system/auth.php @@ -41,9 +41,6 @@ public static function user() throw new \Exception("You must specify a session driver before using the Auth class."); } - // ----------------------------------------------------- - // Get the authentication model. - // ----------------------------------------------------- $model = static::model(); // ----------------------------------------------------- @@ -65,9 +62,6 @@ public static function user() */ public static function login($username, $password) { - // ----------------------------------------------------- - // Get the authentication model. - // ----------------------------------------------------- $model = static::model(); // ----------------------------------------------------- @@ -82,19 +76,10 @@ public static function login($username, $password) // ----------------------------------------------------- $password = (isset($user->salt)) ? Hash::make($password, $user->salt)->value : sha1($password); - // ----------------------------------------------------- - // Verify that the passwords match. - // ----------------------------------------------------- if ($user->password == $password) { - // ----------------------------------------------------- - // Set the user property. - // ----------------------------------------------------- static::$user = $user; - // ----------------------------------------------------- - // Store the user ID in the session. - // ----------------------------------------------------- Session::put(static::$key, $user->id); return true; @@ -111,14 +96,7 @@ public static function login($username, $password) */ public static function logout() { - // ----------------------------------------------------- - // Remove the user ID from the session. - // ----------------------------------------------------- Session::forget(static::$key); - - // ----------------------------------------------------- - // Clear the current user variable. - // ----------------------------------------------------- static::$user = null; } diff --git a/system/cache/driver/file.php b/system/cache/driver/file.php index e51f8b9f..39cb7e8d 100644 --- a/system/cache/driver/file.php +++ b/system/cache/driver/file.php @@ -38,16 +38,13 @@ public function get($key, $default = null) } // -------------------------------------------------- - // Verify that the cache file exists. + // Does the cache item even exist? // -------------------------------------------------- if ( ! file_exists(APP_PATH.'cache/'.$key)) { return $default; } - // -------------------------------------------------- - // Read the contents of the cache file. - // -------------------------------------------------- $cache = file_get_contents(APP_PATH.'cache/'.$key); // -------------------------------------------------- @@ -74,10 +71,6 @@ public function get($key, $default = null) */ public function put($key, $value, $minutes) { - // -------------------------------------------------- - // The expiration time is stored as a UNIX timestamp - // at the beginning of the cache file. - // -------------------------------------------------- file_put_contents(APP_PATH.'cache/'.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); } diff --git a/system/config.php b/system/config.php index 94cc22f9..75664d13 100644 --- a/system/config.php +++ b/system/config.php @@ -17,19 +17,10 @@ class Config { */ public static function get($key) { - // --------------------------------------------- - // Parse the configuration key. - // --------------------------------------------- list($file, $key) = static::parse($key); - // --------------------------------------------- - // Load the configuration file. - // --------------------------------------------- static::load($file); - // --------------------------------------------- - // Return the requested item. - // --------------------------------------------- return (array_key_exists($key, static::$items[$file])) ? static::$items[$file][$key] : null; } @@ -42,19 +33,10 @@ public static function get($key) */ public static function set($file, $value) { - // --------------------------------------------- - // Parse the configuration key. - // --------------------------------------------- list($file, $key) = static::parse($key); - // --------------------------------------------- - // Load the configuration file. - // --------------------------------------------- static::load($file); - // --------------------------------------------- - // Set the item's value. - // --------------------------------------------- static::$items[$file][$key] = $value; } @@ -66,22 +48,13 @@ public static function set($file, $value) */ private static function parse($key) { - // --------------------------------------------- - // Get the key segments. - // --------------------------------------------- $segments = explode('.', $key); - // --------------------------------------------- - // Validate the key format. - // --------------------------------------------- if (count($segments) < 2) { throw new \Exception("Invalid configuration key [$key]."); } - // --------------------------------------------- - // Return the file and item name. - // --------------------------------------------- return array($segments[0], implode('.', array_slice($segments, 1))); } @@ -93,25 +66,16 @@ private static function parse($key) */ public static function load($file) { - // --------------------------------------------- - // If the file has already been loaded, bail. - // --------------------------------------------- if (array_key_exists($file, static::$items)) { return; } - // --------------------------------------------- - // Verify that the configuration file exists. - // --------------------------------------------- if ( ! file_exists($path = APP_PATH.'config/'.$file.EXT)) { throw new \Exception("Configuration file [$file] does not exist."); } - // --------------------------------------------- - // Load the configuration file. - // --------------------------------------------- static::$items[$file] = require $path; } diff --git a/system/cookie.php b/system/cookie.php index 8f24f368..e004c807 100644 --- a/system/cookie.php +++ b/system/cookie.php @@ -53,9 +53,6 @@ public static function forever($key, $value, $path = '/', $domain = null, $secur */ public static function put($key, $value, $minutes = 0, $path = '/', $domain = null, $secure = false) { - // ---------------------------------------------------------- - // If the lifetime is less than zero, delete the cookie. - // ---------------------------------------------------------- if ($minutes < 0) { unset($_COOKIE[$key]); diff --git a/system/crypt.php b/system/crypt.php index 9efba4a9..e00cd98f 100644 --- a/system/crypt.php +++ b/system/crypt.php @@ -48,14 +48,7 @@ public static function encrypt($value) mt_srand(); } - // ----------------------------------------------------- - // Create the input vector. - // ----------------------------------------------------- $iv = mcrypt_create_iv(static::iv_size(), $random); - - // ----------------------------------------------------- - // Encrypt the value using MCrypt. - // ----------------------------------------------------- $value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv); // ----------------------------------------------------- @@ -72,14 +65,8 @@ public static function encrypt($value) */ public static function decrypt($value) { - // ----------------------------------------------------- - // Decode the base64 value. - // ----------------------------------------------------- $value = base64_decode($value, true); - // ----------------------------------------------------- - // Validate the base64 conversion. - // ----------------------------------------------------- if ( ! $value) { throw new \Exception('Decryption error. Input value is not valid base64 data.'); @@ -95,9 +82,6 @@ public static function decrypt($value) // ----------------------------------------------------- $value = substr($value, static::iv_size()); - // ----------------------------------------------------- - // Decrypt the value using MCrypt. - // ----------------------------------------------------- return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0"); } @@ -108,9 +92,6 @@ public static function decrypt($value) */ private static function key() { - // ----------------------------------------------------- - // Validate the application key. - // ----------------------------------------------------- if (is_null($key = Config::get('application.key')) or $key == '') { throw new \Exception("The encryption class can not be used without an encryption key."); diff --git a/system/db.php b/system/db.php index b4a488f2..bcfd2841 100644 --- a/system/db.php +++ b/system/db.php @@ -17,9 +17,6 @@ class DB { */ public static function connection($connection = null) { - // --------------------------------------------------- - // If no connection was given, use the default. - // --------------------------------------------------- if (is_null($connection)) { $connection = Config::get('db.default'); @@ -31,14 +28,8 @@ public static function connection($connection = null) // --------------------------------------------------- if ( ! array_key_exists($connection, static::$connections)) { - // --------------------------------------------------- - // Get the database configurations. - // --------------------------------------------------- $config = Config::get('db.connections'); - // --------------------------------------------------- - // Verify the connection has been defined. - // --------------------------------------------------- if ( ! array_key_exists($connection, $config)) { throw new \Exception("Database connection [$connection] is not defined."); @@ -63,14 +54,8 @@ public static function connection($connection = null) */ public static function query($sql, $bindings = array(), $connection = null) { - // --------------------------------------------------- - // Create a new PDO statement from the SQL. - // --------------------------------------------------- $query = static::connection($connection)->prepare($sql); - // --------------------------------------------------- - // Execute the query with the bindings. - // --------------------------------------------------- $result = $query->execute($bindings); // --------------------------------------------------- diff --git a/system/db/connector.php b/system/db/connector.php index 196170d1..d5aab6d1 100644 --- a/system/db/connector.php +++ b/system/db/connector.php @@ -36,9 +36,6 @@ public static function connect($config) { $connection = new \PDO($config->driver.':host='.$config->host.';dbname='.$config->database, $config->username, $config->password, static::$options); - // --------------------------------------------------- - // Set the correct character set. - // --------------------------------------------------- if (isset($config->charset)) { $connection->prepare("SET NAMES '".$config->charset."'")->execute(); @@ -46,9 +43,6 @@ public static function connect($config) return $connection; } - // --------------------------------------------------- - // If the driver isn't supported, bail out. - // --------------------------------------------------- else { throw new \Exception('Database driver '.$config->driver.' is not supported.'); diff --git a/system/db/eloquent.php b/system/db/eloquent.php index f6070776..6713acbb 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -76,14 +76,7 @@ abstract class Eloquent { */ public static function with() { - // ----------------------------------------------------- - // Create a new model instance. - // ----------------------------------------------------- $model = Eloquent\Factory::make(get_called_class()); - - // ----------------------------------------------------- - // Set the eager relationships. - // ----------------------------------------------------- $model->includes = func_get_args(); return $model; @@ -117,14 +110,8 @@ private function _get() */ private function _first() { - // ----------------------------------------------------- - // Load the hydrated models. - // ----------------------------------------------------- $results = Eloquent\Hydrate::from($this->take(1)); - // ----------------------------------------------------- - // Return the first result. - // ----------------------------------------------------- if (count($results) > 0) { reset($results); @@ -185,11 +172,16 @@ public function has_many_and_belongs_to($model) /** * Save the model to the database. * - * @return void + * @return bool */ public function save() { - Eloquent\Warehouse::store($this); + if ($this->exists and count($this->dirty) == 0) + { + return true; + } + + return Eloquent\Warehouse::store($this); } /** @@ -215,17 +207,11 @@ public function __get($key) // ----------------------------------------------------- $model = $this->$key(); - // ----------------------------------------------------- - // Return the relationship results. - // ----------------------------------------------------- return ($this->relating == 'has_one' or $this->relating == 'belongs_to') ? $this->ignore[$key] = $model->first() : $this->ignore[$key] = $model->get(); } - // ----------------------------------------------------- - // Check the "regular" attributes. - // ----------------------------------------------------- return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null; } @@ -243,9 +229,6 @@ public function __set($key, $value) } else { - // ----------------------------------------------------- - // Add the value to the attributes. - // ----------------------------------------------------- $this->attributes[$key] = $value; $this->dirty[$key] = $value; } @@ -274,17 +257,11 @@ public function __unset($key) */ public function __call($method, $parameters) { - // ----------------------------------------------------- - // Is the "get" method being called? - // ----------------------------------------------------- if ($method == 'get') { return $this->_get(); } - // ----------------------------------------------------- - // Is the "first" method being called? - // ----------------------------------------------------- if ($method == 'first') { return $this->_first(); @@ -312,22 +289,13 @@ public function __call($method, $parameters) */ public static function __callStatic($method, $parameters) { - // ----------------------------------------------------- - // Create a new model instance. - // ----------------------------------------------------- $model = Eloquent\Factory::make(get_called_class()); - // ----------------------------------------------------- - // Do we need to return the entire table? - // ----------------------------------------------------- if ($method == 'get') { return $model->_get(); } - // ----------------------------------------------------- - // Do we need to return the first model from the table? - // ----------------------------------------------------- if ($method == 'first') { return $model->_first(); diff --git a/system/db/eloquent/factory.php b/system/db/eloquent/factory.php index 3d792581..22110700 100644 --- a/system/db/eloquent/factory.php +++ b/system/db/eloquent/factory.php @@ -10,13 +10,10 @@ class Factory { */ public static function make($class) { - // ----------------------------------------------------- - // Create a new model instance. - // ----------------------------------------------------- $model = new $class; // ----------------------------------------------------- - // Set the active query instance on the model. + // Set the fluent query builder on the model. // ----------------------------------------------------- $model->query = \System\DB\Query::table(Meta::table($class)); diff --git a/system/db/eloquent/hydrate.php b/system/db/eloquent/hydrate.php index 925e2915..4b2a563b 100644 --- a/system/db/eloquent/hydrate.php +++ b/system/db/eloquent/hydrate.php @@ -22,17 +22,11 @@ public static function from($eloquent) { foreach ($eloquent->includes as $include) { - // ----------------------------------------------------- - // Verify the relationship is defined. - // ----------------------------------------------------- if ( ! method_exists($eloquent, $include)) { throw new \Exception("Attempting to eager load [$include], but the relationship is not defined."); } - // ----------------------------------------------------- - // Eagerly load the relationship. - // ----------------------------------------------------- static::eagerly($eloquent, $include, $results); } } @@ -49,34 +43,17 @@ public static function from($eloquent) */ private static function base($class, $models) { - // ----------------------------------------------------- - // Initialize the hydrated model array. - // ----------------------------------------------------- $results = array(); - // ----------------------------------------------------- - // Hydrate the models from the results. - // ----------------------------------------------------- foreach ($models as $model) { - // ----------------------------------------------------- - // Instantiate a new model instance. - // ----------------------------------------------------- $result = new $class; - // ----------------------------------------------------- - // Set the model's attributes. - // ----------------------------------------------------- $result->attributes = (array) $model; - - // ----------------------------------------------------- - // Indicate that the model already exists. - // ----------------------------------------------------- $result->exists = true; // ----------------------------------------------------- - // Add the hydrated model to the array of models. - // The array is keyed by the primary keys of the models. + // The results are keyed by the ID on the record. // ----------------------------------------------------- $results[$result->id] = $result; } @@ -107,13 +84,9 @@ private static function eagerly($eloquent, $include, &$results) unset($eloquent->attributes[$spoof]); // ----------------------------------------------------- - // Reset the WHERE clause on the query. + // Reset the WHERE clause and bindings on the query. // ----------------------------------------------------- $model->query->where = 'WHERE 1 = 1'; - - // ----------------------------------------------------- - // Reset the bindings on the query. - // ----------------------------------------------------- $model->query->bindings = array(); // ----------------------------------------------------- @@ -124,23 +97,14 @@ private static function eagerly($eloquent, $include, &$results) $result->ignore[$include] = (strpos($eloquent->relating, 'has_many') === 0) ? array() : null; } - // ----------------------------------------------------- - // Eagerly load a 1:1 or 1:* relationship. - // ----------------------------------------------------- if ($eloquent->relating == 'has_one' or $eloquent->relating == 'has_many') { static::eagerly_load_one_or_many($eloquent->relating_key, $eloquent->relating, $include, $model, $results); } - // ----------------------------------------------------- - // Eagerly load a 1:1 (belonging) relationship. - // ----------------------------------------------------- elseif ($eloquent->relating == 'belongs_to') { static::eagerly_load_belonging($eloquent->relating_key, $include, $model, $results); } - // ----------------------------------------------------- - // Eagerly load a *:* relationship. - // ----------------------------------------------------- else { static::eagerly_load_many_to_many($eloquent->relating_key, $eloquent->relating_table, strtolower(get_class($eloquent)).'_id', $include, $model, $results); diff --git a/system/db/eloquent/relate.php b/system/db/eloquent/relate.php index 2b4df758..18973003 100644 --- a/system/db/eloquent/relate.php +++ b/system/db/eloquent/relate.php @@ -11,14 +11,7 @@ class Relate { */ public static function has_one($model, $eloquent) { - // ----------------------------------------------------- - // Set the relating type. - // ----------------------------------------------------- $eloquent->relating = __FUNCTION__; - - // ----------------------------------------------------- - // Return the Eloquent model. - // ----------------------------------------------------- return static::has_one_or_many($model, $eloquent); } @@ -31,14 +24,7 @@ public static function has_one($model, $eloquent) */ public static function has_many($model, $eloquent) { - // ----------------------------------------------------- - // Set the relating type. - // ----------------------------------------------------- $eloquent->relating = __FUNCTION__; - - // ----------------------------------------------------- - // Return the Eloquent model. - // ----------------------------------------------------- return static::has_one_or_many($model, $eloquent); } @@ -51,11 +37,7 @@ public static function has_many($model, $eloquent) */ private static function has_one_or_many($model, $eloquent) { - // ----------------------------------------------------- - // Set the relating key. - // ----------------------------------------------------- $eloquent->relating_key = \System\Str::lower(get_class($eloquent)).'_id'; - return Factory::make($model)->where($eloquent->relating_key, '=', $eloquent->id); } @@ -69,19 +51,9 @@ private static function has_one_or_many($model, $eloquent) */ public static function belongs_to($caller, $model, $eloquent) { - // ----------------------------------------------------- - // Set the relating type. - // ----------------------------------------------------- $eloquent->relating = __FUNCTION__; - - // ----------------------------------------------------- - // Set the relating key. - // ----------------------------------------------------- $eloquent->relating_key = $caller['function'].'_id'; - // ----------------------------------------------------- - // Return the Eloquent model. - // ----------------------------------------------------- return Factory::make($model)->where('id', '=', $eloquent->attributes[$eloquent->relating_key]); } @@ -98,31 +70,12 @@ public static function has_many_and_belongs_to($model, $eloquent) // Get the models involved in the relationship. // ----------------------------------------------------- $models = array(\System\Str::lower($model), \System\Str::lower(get_class($eloquent))); - - // ----------------------------------------------------- - // Sort the model names involved in the relationship. - // ----------------------------------------------------- sort($models); - // ----------------------------------------------------- - // Get the intermediate table name, which is the names - // of the two related models alphabetized. - // ----------------------------------------------------- $eloquent->relating_table = implode('_', $models); - - // ----------------------------------------------------- - // Set the relating type. - // ----------------------------------------------------- $eloquent->relating = __FUNCTION__; - - // ----------------------------------------------------- - // Set the relating key. - // ----------------------------------------------------- $eloquent->relating_key = $eloquent->relating_table.'.'.\System\Str::lower(get_class($eloquent)).'_id'; - // ----------------------------------------------------- - // Return the Eloquent model. - // ----------------------------------------------------- return Factory::make($model) ->select(Meta::table($model).'.*') ->join($eloquent->relating_table, Meta::table($model).'.id', '=', $eloquent->relating_table.'.'.\System\Str::lower($model).'_id') diff --git a/system/db/eloquent/warehouse.php b/system/db/eloquent/warehouse.php index 9eff22ef..5f5b1a57 100644 --- a/system/db/eloquent/warehouse.php +++ b/system/db/eloquent/warehouse.php @@ -6,13 +6,10 @@ class Warehouse { * Save an Eloquent model to the database. * * @param object $eloquent - * @return void + * @return bool */ public static function store($eloquent) { - // ----------------------------------------------------- - // Get the model name. - // ----------------------------------------------------- $model = get_class($eloquent); // ----------------------------------------------------- @@ -21,30 +18,25 @@ public static function store($eloquent) $eloquent->query = \System\DB\Query::table(Meta::table($model)); // ----------------------------------------------------- - // Set the activity timestamps. + // Set the creation and update timestamps. // ----------------------------------------------------- if (property_exists($model, 'timestamps') and $model::$timestamps) { static::timestamp($eloquent); } - // ----------------------------------------------------- - // If the model exists in the database, update it. - // Otherwise, insert the model and set the ID. - // ----------------------------------------------------- if ($eloquent->exists) { - return $eloquent->query->where('id', '=', $eloquent->attributes['id'])->update($eloquent->dirty); + return ($eloquent->query->where('id', '=', $eloquent->attributes['id'])->update($eloquent->dirty) == 1) ? true : false; } else { $eloquent->attributes['id'] = $eloquent->query->insert_get_id($eloquent->attributes); } - // ----------------------------------------------------- - // Set the existence flag to true. - // ----------------------------------------------------- $eloquent->exists = true; + + return true; } /** diff --git a/system/db/query.php b/system/db/query.php index 16fb634a..70b919b3 100644 --- a/system/db/query.php +++ b/system/db/query.php @@ -81,14 +81,7 @@ class Query { */ public function __construct($table, $connection = null) { - // --------------------------------------------------- - // Set the database connection name. - // --------------------------------------------------- $this->connection = (is_null($connection)) ? \System\Config::get('db.default') : $connection; - - // --------------------------------------------------- - // Build the FROM clause. - // --------------------------------------------------- $this->from = 'FROM '.$this->wrap($this->table = $table); } @@ -122,9 +115,6 @@ public function distinct() */ public function select() { - // --------------------------------------------------- - // Handle DISTINCT selections. - // --------------------------------------------------- $this->select = ($this->distinct) ? 'SELECT DISTINCT ' : 'SELECT '; // --------------------------------------------------- @@ -372,15 +362,7 @@ public function take($value) */ public function find($id) { - // --------------------------------------------------- - // Set the primary key. - // --------------------------------------------------- - $this->where('id', '=', $id); - - // --------------------------------------------------- - // Get the first result. - // --------------------------------------------------- - return $this->first(); + return $this->where('id', '=', $id)->first(); } /** @@ -400,9 +382,6 @@ public function first() */ public function get() { - // --------------------------------------------------- - // Initialize the SELECT clause if it's null. - // --------------------------------------------------- if (is_null($this->select)) { call_user_func_array(array($this, 'select'), (count(func_get_args()) > 0) ? func_get_args() : array('*')); @@ -420,14 +399,8 @@ public function get() */ private function aggregate($aggregator, $column) { - // --------------------------------------------------- - // Build the SELECT clause. - // --------------------------------------------------- $this->select = 'SELECT '.$aggregator.'('.$this->wrap($column).') AS '.$this->wrap('aggregate'); - // --------------------------------------------------- - // Execute the statement. - // --------------------------------------------------- $results = \System\DB::query(Query\Compiler::select($this), $this->bindings); return $results[0]->aggregate; @@ -452,54 +425,28 @@ public function insert($values) */ public function insert_get_id($values) { - // --------------------------------------------------- - // Compile the SQL statement. - // --------------------------------------------------- $sql = Query\Compiler::insert($this, $values); // --------------------------------------------------- - // The Postgres PDO implementation does not cleanly - // implement the last insert ID function. So, we'll - // use the RETURNING clause available in Postgres. + // Postgres. // --------------------------------------------------- if (\System\DB::connection($this->connection)->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'pgsql') { - // --------------------------------------------------- - // Add the RETURNING clause to the SQL. - // --------------------------------------------------- $sql .= ' RETURNING '.$this->wrap('id'); - // --------------------------------------------------- - // Prepare the PDO statement. - // --------------------------------------------------- $query = \System\DB::connection($this->connection)->prepare($sql); - - // --------------------------------------------------- - // Execute the PDO statement. - // --------------------------------------------------- $query->execute(array_values($values)); - // --------------------------------------------------- - // Fetch the insert ID from the results. - // --------------------------------------------------- $result = $query->fetch(\PDO::FETCH_ASSOC); return $result['id']; } // --------------------------------------------------- - // When using MySQL or SQLite, we can just use the PDO - // last insert ID function. + // MySQL and SQLite. // --------------------------------------------------- else { - // --------------------------------------------------- - // Execute the statement. - // --------------------------------------------------- \System\DB::query($sql, array_values($values), $this->connection); - - // --------------------------------------------------- - // Get the last insert ID. - // --------------------------------------------------- return \System\DB::connection($this->connection)->lastInsertId(); } } @@ -523,17 +470,11 @@ public function update($values) */ public function delete($id = null) { - // --------------------------------------------------- - // Set the primary key. - // --------------------------------------------------- if ( ! is_null($id)) { $this->where('id', '=', $id); } - // --------------------------------------------------- - // Execute the statement. - // --------------------------------------------------- return \System\DB::query(Query\Compiler::delete($this), $this->bindings, $this->connection); } @@ -555,9 +496,6 @@ public function wrap($value, $wrap = '"') $wrap = '`'; } - // --------------------------------------------------- - // Wrap the element in keyword identifiers. - // --------------------------------------------------- return implode('.', array_map(function($segment) use ($wrap) {return ($segment != '*') ? $wrap.$segment.$wrap : $segment;}, explode('.', $value))); } diff --git a/system/db/query/compiler.php b/system/db/query/compiler.php index 53adcb80..61889f98 100644 --- a/system/db/query/compiler.php +++ b/system/db/query/compiler.php @@ -10,30 +10,18 @@ class Compiler { */ public static function select($query) { - // --------------------------------------------------- - // Add the SELECT, FROM, and WHERE clauses. - // --------------------------------------------------- $sql = $query->select.' '.$query->from.' '.$query->where; - // --------------------------------------------------- - // Add the ORDER BY clause. - // --------------------------------------------------- if (count($query->orderings) > 0) { $sql .= ' ORDER BY '.implode(', ', $query->orderings); } - // --------------------------------------------------- - // Add the LIMIT. - // --------------------------------------------------- if ( ! is_null($query->limit)) { $sql .= ' LIMIT '.$query->limit; } - // --------------------------------------------------- - // Add the OFFSET. - // --------------------------------------------------- if ( ! is_null($query->offset)) { $sql .= ' OFFSET '.$query->offset; @@ -51,9 +39,6 @@ public static function select($query) */ public static function insert($query, $values) { - // --------------------------------------------------- - // Start the query. Add the table name. - // --------------------------------------------------- $sql = 'INSERT INTO '.$query->table.' ('; // --------------------------------------------------- @@ -66,9 +51,6 @@ public static function insert($query, $values) $columns[] = $query->wrap($column); } - // --------------------------------------------------- - // Concatenate the column names and values. - // --------------------------------------------------- return $sql .= implode(', ', $columns).') VALUES ('.$query->parameterize($values).')'; } @@ -81,13 +63,10 @@ public static function insert($query, $values) */ public static function update($query, $values) { - // --------------------------------------------------- - // Start the query. Add the table name. - // --------------------------------------------------- $sql = 'UPDATE '.$query->table.' SET '; // --------------------------------------------------- - // Wrap each column name in keyword identifiers. + // Add each column set the query. // --------------------------------------------------- $columns = array(); @@ -96,9 +75,6 @@ public static function update($query, $values) $columns[] = $query->wrap($column).' = ?'; } - // --------------------------------------------------- - // Concatenate the column names and the WHERE clause. - // --------------------------------------------------- return $sql .= implode(', ', $columns).' '.$query->where; } diff --git a/system/download.php b/system/download.php index 60567375..a8785d8b 100644 --- a/system/download.php +++ b/system/download.php @@ -109,17 +109,11 @@ class Download { */ public static function file($path, $name = null) { - // ------------------------------------------------- - // If no name was specified, just use the basename. - // ------------------------------------------------- if (is_null($name)) { $name = basename($path); } - // ------------------------------------------------- - // Set the headers to force the download to occur. - // ------------------------------------------------- return Response::make(file_get_contents($path))->header('Content-Description', 'File Transfer') ->header('Content-Type', static::mime(pathinfo($path, PATHINFO_EXTENSION))) ->header('Content-Disposition', 'attachment; filename="'.$name.'"') diff --git a/system/error.php b/system/error.php index e29a3fe9..b11b7e76 100644 --- a/system/error.php +++ b/system/error.php @@ -72,9 +72,6 @@ public static function handle($e) if (Config::get('error.detail')) { - // ----------------------------------------------------- - // Build the error view. - // ----------------------------------------------------- $view = View::make('error/exception') ->bind('severity', $severity) ->bind('message', $message) @@ -83,16 +80,10 @@ public static function handle($e) ->bind('trace', $e->getTraceAsString()) ->bind('contexts', static::context($file, $e->getLine())); - // ----------------------------------------------------- - // Send the detailed error response. - // ----------------------------------------------------- Response::make($view, 500)->send(); } else { - // ----------------------------------------------------- - // Send the generic error response. - // ----------------------------------------------------- Response::make(View::make('error/500'), 500)->send(); } @@ -109,19 +100,10 @@ public static function handle($e) */ private static function context($path, $line, $padding = 5) { - // ----------------------------------------------------- - // Verify that the file exists. - // ----------------------------------------------------- if (file_exists($path)) { - // ----------------------------------------------------- - // Get the contents of the file. - // ----------------------------------------------------- $file = file($path, FILE_IGNORE_NEW_LINES); - // ----------------------------------------------------- - // Unshift the array. - // ----------------------------------------------------- array_unshift($file, ''); // ----------------------------------------------------- @@ -144,9 +126,6 @@ private static function context($path, $line, $padding = 5) $length = null; } - // ----------------------------------------------------- - // Return the context. - // ----------------------------------------------------- return array_slice($file, $start, $length, true); } diff --git a/system/filter.php b/system/filter.php index 6b72719d..20b492ca 100644 --- a/system/filter.php +++ b/system/filter.php @@ -18,9 +18,6 @@ class Filter { */ public static function call($filters, $parameters = array()) { - // -------------------------------------------------------------- - // Load the route filters. - // -------------------------------------------------------------- if (is_null(static::$filters)) { static::$filters = require APP_PATH.'filters'.EXT; @@ -28,9 +25,6 @@ public static function call($filters, $parameters = array()) foreach (explode(', ', $filters) as $filter) { - // -------------------------------------------------------------- - // Verify that the filter is defined. - // -------------------------------------------------------------- if ( ! isset(static::$filters[$filter])) { throw new \Exception("Route filter [$filter] is not defined."); @@ -39,7 +33,8 @@ public static function call($filters, $parameters = array()) $response = call_user_func_array(static::$filters[$filter], $parameters); // -------------------------------------------------------------- - // If the filter returned a response, return it. + // If the filter returned a response, return it since route + // filters can override route methods. // -------------------------------------------------------------- if ( ! is_null($response)) { diff --git a/system/form.php b/system/form.php index b9cfe966..ddbe2b5c 100644 --- a/system/form.php +++ b/system/form.php @@ -20,32 +20,16 @@ public static function open($action = null, $method = 'POST', $attributes = arra $action = Request::uri(); } - // ------------------------------------------------------- - // Prepare the action URL. - // ------------------------------------------------------- $action = URL::to($action); - // ------------------------------------------------------- - // Set the action attribute. - // ------------------------------------------------------- $attributes['action'] = $action; - - // ------------------------------------------------------- - // Set the method attribute. - // ------------------------------------------------------- $attributes['method'] = ($method == 'GET' or $method == 'POST') ? $method : 'POST'; - // ------------------------------------------------------- - // Set the default character set. - // ------------------------------------------------------- if ( ! array_key_exists('accept-charset', $attributes)) { $attributes['accept-charset'] = 'UTF-8'; } - // ------------------------------------------------------- - // Build the form tag. - // ------------------------------------------------------- $html = ''; // ------------------------------------------------------- @@ -79,9 +63,6 @@ public static function token() */ public static function raw_token() { - // ------------------------------------------------------- - // Verify that sessions are enabled. - // ------------------------------------------------------- if (Config::get('session.driver') == '') { throw new \Exception('Sessions must be enabled to retrieve a CSRF token.'); @@ -204,9 +185,6 @@ public static function radio($name, $value = null, $checked = false, $attributes */ private static function checkable($type, $name, $value, $checked, $attributes) { - // ------------------------------------------------------- - // Set the checked attribute. - // ------------------------------------------------------- if ($checked === true) { $attributes['checked'] = 'checked'; @@ -225,9 +203,6 @@ private static function checkable($type, $name, $value, $checked, $attributes) */ public static function textarea($name, $value = '', $attributes = array()) { - // ------------------------------------------------------- - // Add the name to the attributes. - // ------------------------------------------------------- $attributes['name'] = $name; // ------------------------------------------------------- @@ -260,36 +235,17 @@ public static function textarea($name, $value = '', $attributes = array()) */ public static function select($name, $options = array(), $selected = null, $attributes = array()) { - // ------------------------------------------------------- - // Set the name attribute. - // ------------------------------------------------------- $attributes['name'] = $name; - // ------------------------------------------------------- - // Initialize the options array. - // ------------------------------------------------------- $html_options = array(); - // ------------------------------------------------------- - // Build the options in HTML. - // ------------------------------------------------------- foreach ($options as $value => $display) { $option_attributes = array(); - // ------------------------------------------------------- - // Set the value attribute. - // ------------------------------------------------------- $option_attributes['value'] = $value; - - // ------------------------------------------------------- - // Set the selected attribute. - // ------------------------------------------------------- $option_attributes['selected'] = ($value == $selected) ? 'selected' : null; - // ------------------------------------------------------- - // Add the option HTML to the array of options. - // ------------------------------------------------------- $html_options[] = ''.$display.''; } @@ -306,19 +262,8 @@ public static function select($name, $options = array(), $selected = null, $attr */ private static function input($type, $name, $value = null, $attributes = array()) { - // ------------------------------------------------------- - // Set the type attribute. - // ------------------------------------------------------- $attributes['type'] = $type; - - // ------------------------------------------------------- - // Set the name attribute. - // ------------------------------------------------------- $attributes['name'] = $name; - - // ------------------------------------------------------- - // Set the value attribute. - // ------------------------------------------------------- $attributes['value'] = $value; return ''.PHP_EOL; diff --git a/system/hash.php b/system/hash.php index 2d14f267..b044c0b7 100644 --- a/system/hash.php +++ b/system/hash.php @@ -25,14 +25,7 @@ class Hash { */ public function __construct($value, $salt = null) { - // -------------------------------------------------------------- - // Get a random salt to hash the value with. - // -------------------------------------------------------------- $this->salt = (is_null($salt)) ? Str::random(16) : $salt; - - // -------------------------------------------------------------- - // Perform a salted, SHA-1 hash on the value. - // -------------------------------------------------------------- $this->value = sha1($value.$this->salt); } diff --git a/system/html.php b/system/html.php index 7c6eac52..fa8a35f7 100644 --- a/system/html.php +++ b/system/html.php @@ -66,9 +66,6 @@ public static function mailto($email, $title = null, $attributes = array()) // ------------------------------------------------------- $email = static::email($email); - // ------------------------------------------------------- - // If no title is specified, just use the e-mail address. - // ------------------------------------------------------- if (is_null($title)) { $title = $email; @@ -98,11 +95,7 @@ public static function email($email) */ public static function image($url, $alt = '', $attributes = array()) { - // ------------------------------------------------------- - // Add the "alt" tag to the attributes. - // ------------------------------------------------------- $attributes['alt'] = Str::entities($alt); - return ''; } @@ -162,33 +155,19 @@ public static function ul($list, $attributes = array()) */ private static function list_elements($type, $list, $attributes) { - // ------------------------------------------------------- - // Verify the list is an array. - // ------------------------------------------------------- if ( ! is_array($list)) { return ''; } - // ------------------------------------------------------- - // Initialize the output value. - // ------------------------------------------------------- $html = ''; - // ------------------------------------------------------- - // Add the list items. - // ------------------------------------------------------- foreach ($list as $key => $value) { $html .= '
  • '.Str::entities($value).'
  • '; } - // ------------------------------------------------------- - // Build the list opening tag. - // ------------------------------------------------------- - $start = '<'.$type.static::attributes($attributes).'>'; - - return $start.$html.''; + return '<'.$type.static::attributes($attributes).'>'.$html.''; } /** @@ -203,23 +182,12 @@ public static function attributes($attributes) foreach ($attributes as $key => $value) { - // ------------------------------------------------------- - // If the value is null, skip it. - // ------------------------------------------------------- - if (is_null($value)) + if ( ! is_null($value)) { - continue; + $html[] = $key.'="'.Str::entities($value).'"'; } - - // ------------------------------------------------------- - // Add the HTML attribute to the array of attributes. - // ------------------------------------------------------- - $html[] = $key.'="'.Str::entities($value).'"'; } - // ------------------------------------------------------- - // Concatenate all of the attributes together. - // ------------------------------------------------------- if (count($html) > 0) { return ' '.implode(' ', $html); diff --git a/system/inflector.php b/system/inflector.php index f732127e..cc7e4fbe 100644 --- a/system/inflector.php +++ b/system/inflector.php @@ -121,9 +121,6 @@ class Inflector { */ public static function plural($value) { - // ----------------------------------------------------- - // Have we already converted this word? - // ----------------------------------------------------- if (array_key_exists($value, static::$plural_cache)) { return static::$plural_cache[$value]; @@ -172,9 +169,6 @@ public static function plural($value) */ public static function singular($value) { - // ----------------------------------------------------- - // Have we already converted this word? - // ----------------------------------------------------- if (array_key_exists($value, static::$singular_cache)) { return static::$singular_cache[$value]; diff --git a/system/input.php b/system/input.php index 418ad92a..ba9d75df 100644 --- a/system/input.php +++ b/system/input.php @@ -40,11 +40,7 @@ public static function has_old($key) */ public static function get($key = null, $default = null) { - // ------------------------------------------------- - // Hydrate the input data for the request. - // ------------------------------------------------- static::hydrate(); - return static::from_array(static::$input, $key, $default); } @@ -57,9 +53,6 @@ public static function get($key = null, $default = null) */ public static function old($key = null, $default = null) { - // ------------------------------------------------- - // Verify that sessions are enabled. - // ------------------------------------------------- if (Config::get('session.driver') == '') { throw new \Exception("Sessions must be enabled to retrieve old input data."); @@ -69,7 +62,7 @@ public static function old($key = null, $default = null) } /** - * Get an item from an array. + * Get an item from an array. If no key is specified, the entire array will be returned. * * @param array $array * @param string $key @@ -78,9 +71,6 @@ public static function old($key = null, $default = null) */ private static function from_array($array, $key, $default) { - // ------------------------------------------------- - // If no key is given, return the entire array. - // ------------------------------------------------- if (is_null($key)) { return $array; diff --git a/system/lang.php b/system/lang.php index 72c1a488..ad5620f7 100644 --- a/system/lang.php +++ b/system/lang.php @@ -60,22 +60,13 @@ public static function line($key) */ public function get($language = null) { - // -------------------------------------------------------------- - // If no language was specified, use the default language. - // -------------------------------------------------------------- if (is_null($language)) { $language = Config::get('application.language'); } - // -------------------------------------------------------------- - // Extract the file and item from the key. - // -------------------------------------------------------------- list($file, $line) = $this->parse($this->key); - // -------------------------------------------------------------- - // Load the language file. - // -------------------------------------------------------------- $this->load($file, $language); // -------------------------------------------------------------- @@ -109,22 +100,13 @@ public function get($language = null) */ private function parse($key) { - // --------------------------------------------- - // Get the key segments. - // --------------------------------------------- $segments = explode('.', $key); - // --------------------------------------------- - // Validate the key format. - // --------------------------------------------- if (count($segments) < 2) { throw new \Exception("Invalid language key [$key]."); } - // --------------------------------------------- - // Return the file and item name. - // --------------------------------------------- return array($segments[0], implode('.', array_slice($segments, 1))); } @@ -137,16 +119,13 @@ private function parse($key) */ private function load($file, $language) { - // -------------------------------------------------------------- - // Do not load the file if it has already been loaded. - // -------------------------------------------------------------- if (in_array($language.$file, static::$loaded)) { return; } // -------------------------------------------------------------- - // Does the language file exist? + // Load the language file into the array of lines. // -------------------------------------------------------------- if (file_exists($path = APP_PATH.'lang/'.$language.'/'.$file.EXT)) { @@ -157,9 +136,6 @@ private function load($file, $language) throw new \Exception("Language file [$file] does not exist for language [$language]."); } - // -------------------------------------------------------------- - // Add the file to the array of loaded files. - // -------------------------------------------------------------- static::$loaded[] = $language.$file; } diff --git a/system/loader.php b/system/loader.php index aa457390..cb0db2d2 100644 --- a/system/loader.php +++ b/system/loader.php @@ -18,30 +18,18 @@ return class_alias($aliases[$class], $class); } - // ---------------------------------------------------------- - // Check for the class in the system directory. - // ---------------------------------------------------------- if (file_exists($path = BASE_PATH.$file.EXT)) { require $path; } - // ---------------------------------------------------------- - // Check for the class in the models directory. - // ---------------------------------------------------------- elseif (file_exists($path = APP_PATH.'models/'.$file.EXT)) { require $path; } - // ---------------------------------------------------------- - // Check for the class in the packages directory. - // ---------------------------------------------------------- elseif (file_exists($path = APP_PATH.'packages/'.$file.EXT)) { require $path; } - // ---------------------------------------------------------- - // Check for the class in the application directory. - // ---------------------------------------------------------- elseif (file_exists($path = APP_PATH.$file.EXT)) { require $path; diff --git a/system/log.php b/system/log.php index cde5021b..2a54fb0e 100644 --- a/system/log.php +++ b/system/log.php @@ -69,14 +69,7 @@ public static function write($type, $message) // ----------------------------------------------------- $file = $directory.'/'.date('d').EXT; - // ----------------------------------------------------- - // Write the message to the log. - // ----------------------------------------------------- file_put_contents($file, date('Y-m-d H:i:s').' '.$type.' - '.$message.PHP_EOL, LOCK_EX | FILE_APPEND); - - // ----------------------------------------------------- - // Set the log file permissions. - // ----------------------------------------------------- chmod($file, 0666); } @@ -88,14 +81,7 @@ public static function write($type, $message) */ private static function make_directory($directory) { - // ----------------------------------------------------- - // Create the directory. - // ----------------------------------------------------- mkdir($directory, 02777); - - // ----------------------------------------------------- - // Set the directory permissions. - // ----------------------------------------------------- chmod($directory, 02777); } diff --git a/system/memcached.php b/system/memcached.php index 7ba1b4cd..c07d7416 100644 --- a/system/memcached.php +++ b/system/memcached.php @@ -18,17 +18,11 @@ public static function instance() { if (is_null(static::$instance)) { - // ----------------------------------------------------- - // Verify that the Memcache extension is installed. - // ----------------------------------------------------- if ( ! class_exists('Memcache')) { throw new \Exception('Attempting to use Memcached, but the Memcached PHP extension is not installed on this server.'); } - // ----------------------------------------------------- - // Instantiate the Memcache class. - // ----------------------------------------------------- $memcache = new \Memcache; // ----------------------------------------------------- diff --git a/system/redirect.php b/system/redirect.php index 5655d512..029432ca 100644 --- a/system/redirect.php +++ b/system/redirect.php @@ -13,14 +13,8 @@ class Redirect { */ public static function to($url, $method = 'location', $status = 302, $https = false) { - // ------------------------------------------------- - // Prepare the URL. - // ------------------------------------------------- $url = URL::to($url, $https); - // ------------------------------------------------- - // Return the redirect response. - // ------------------------------------------------- return ($method == 'refresh') ? Response::make('', $status)->header('Refresh', '0;url='.$url) : Response::make('', $status)->header('Location', $url); diff --git a/system/request.php b/system/request.php index f2073513..32da45ba 100644 --- a/system/request.php +++ b/system/request.php @@ -16,33 +16,21 @@ class Request { */ public static function uri() { - // -------------------------------------------------------------- - // Have we already determined the URI? - // -------------------------------------------------------------- if ( ! is_null(static::$uri)) { return static::$uri; } - // -------------------------------------------------------------- - // Use the PATH_INFO variable if it is available. - // -------------------------------------------------------------- if (isset($_SERVER['PATH_INFO'])) { return static::$uri = static::tidy($_SERVER['PATH_INFO']); } - // -------------------------------------------------------------- - // If the server REQUEST_URI variable is not available, bail out. - // -------------------------------------------------------------- if ( ! isset($_SERVER['REQUEST_URI'])) { throw new \Exception('Unable to determine the request URI.'); } - // -------------------------------------------------------------- - // Get the PHP_URL_PATH of the request URI. - // -------------------------------------------------------------- $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); // -------------------------------------------------------------- diff --git a/system/response.php b/system/response.php index 97e20273..352371e6 100644 --- a/system/response.php +++ b/system/response.php @@ -120,9 +120,6 @@ public static function view($view, $status = 200) */ public function send() { - // ------------------------------------------------- - // Set the content type if it has not been set. - // ------------------------------------------------- if ( ! array_key_exists('Content-Type', $this->headers)) { $this->header('Content-Type', 'text/html; charset=utf-8'); @@ -133,16 +130,10 @@ public function send() // ------------------------------------------------- if ( ! headers_sent()) { - // ------------------------------------------------- - // Send the HTTP protocol and status code. - // ------------------------------------------------- $protocol = (isset($_SERVER['SERVER_PROTOCOL'])) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1'; header($protocol.' '.$this->status.' '.$this->statuses[$this->status]); - // ------------------------------------------------- - // Send the rest of the headers. - // ------------------------------------------------- foreach ($this->headers as $name => $value) { header($name.': '.$value, true); diff --git a/system/route.php b/system/route.php index 26a3fd5f..5f89d53f 100644 --- a/system/route.php +++ b/system/route.php @@ -66,9 +66,6 @@ public function call() } } - // -------------------------------------------------------------- - // Make sure the response is a Response instance. - // -------------------------------------------------------------- $response = ( ! $response instanceof Response) ? new Response($response) : $response; // -------------------------------------------------------------- diff --git a/system/router.php b/system/router.php index 6f8d0ea2..9d2d4f4a 100644 --- a/system/router.php +++ b/system/router.php @@ -26,13 +26,10 @@ class Router { public static function route($method, $uri) { // -------------------------------------------------------------- - // Add a forward slash to the URI if necessary. + // Force the URI to have a forward slash. // -------------------------------------------------------------- $uri = ($uri != '/') ? '/'.$uri : $uri; - // -------------------------------------------------------------- - // Load all of the application routes. - // -------------------------------------------------------------- static::$routes = require APP_PATH.'routes'.EXT; // -------------------------------------------------------------- @@ -54,19 +51,10 @@ public static function route($method, $uri) // -------------------------------------------------------------- if (strpos($keys, '(') !== false or strpos($keys, ',') !== false ) { - // -------------------------------------------------------------- - // Multiple routes can be assigned to a callback using commas. - // -------------------------------------------------------------- foreach (explode(', ', $keys) as $route) { - // -------------------------------------------------------------- - // Change wildcards into regular expressions. - // -------------------------------------------------------------- $route = str_replace(':num', '[0-9]+', str_replace(':any', '.+', $route)); - // -------------------------------------------------------------- - // Test the route for a match. - // -------------------------------------------------------------- if (preg_match('#^'.$route.'$#', $method.' '.$uri)) { return new Route($callback, static::parameters(explode('/', $uri), explode('/', $route))); @@ -84,28 +72,14 @@ public static function route($method, $uri) */ public static function find($name) { - // ---------------------------------------------------- - // Have we already looked up this named route? - // ---------------------------------------------------- if (array_key_exists($name, static::$names)) { return static::$names[$name]; } - // ---------------------------------------------------- - // Instantiate the recursive array iterator. - // ---------------------------------------------------- $arrayIterator = new \RecursiveArrayIterator(static::$routes); - - // ---------------------------------------------------- - // Instantiate the recursive iterator iterator. - // ---------------------------------------------------- $recursiveIterator = new \RecursiveIteratorIterator($arrayIterator); - // ---------------------------------------------------- - // Iterate through the routes searching for a route - // name that matches the given name. - // ---------------------------------------------------- foreach ($recursiveIterator as $iterator) { $route = $recursiveIterator->getSubIterator(); @@ -128,9 +102,6 @@ private static function parameters($uri_segments, $route_segments) { $parameters = array(); - // -------------------------------------------------------------- - // Spin through the route segments looking for parameters. - // -------------------------------------------------------------- for ($i = 0; $i < count($route_segments); $i++) { // -------------------------------------------------------------- diff --git a/system/session.php b/system/session.php index 0d4b1230..5059aa16 100644 --- a/system/session.php +++ b/system/session.php @@ -63,9 +63,6 @@ public static function load() static::put('csrf_token', Str::random(16)); } - // ----------------------------------------------------- - // Set the last activity timestamp for the user. - // ----------------------------------------------------- static::$session['last_activity'] = time(); } @@ -120,14 +117,8 @@ public static function get($key, $default = null) */ public static function once($key, $default = null) { - // ----------------------------------------------------- - // Get the item from the session. - // ----------------------------------------------------- $value = static::get($key, $default); - // ----------------------------------------------------- - // Delete the item from the session. - // ----------------------------------------------------- static::forget($key); return $value; @@ -185,14 +176,7 @@ public static function flush() */ public static function regenerate() { - // ----------------------------------------------------- - // Delete the old session from storage. - // ----------------------------------------------------- static::driver()->delete(static::$session['id']); - - // ----------------------------------------------------- - // Create a new session ID. - // ----------------------------------------------------- static::$session['id'] = Str::random(40); } @@ -203,31 +187,17 @@ public static function regenerate() */ public static function close() { - // ----------------------------------------------------- - // Flash the old input data to the session. - // ----------------------------------------------------- static::flash('laravel_old_input', Input::get()); - - // ----------------------------------------------------- - // Age the session flash data. - // ----------------------------------------------------- static::age_flash(); - // ----------------------------------------------------- - // Save the session to storage. - // ----------------------------------------------------- static::driver()->save(static::$session); + // ----------------------------------------------------- + // Set the session cookie. + // ----------------------------------------------------- if ( ! headers_sent()) { - // ----------------------------------------------------- - // Calculate the cookie lifetime. - // ----------------------------------------------------- $lifetime = (Config::get('session.expire_on_close')) ? 0 : Config::get('session.lifetime'); - - // ----------------------------------------------------- - // Write the session cookie. - // ----------------------------------------------------- Cookie::put('laravel_session', static::$session['id'], $lifetime, Config::get('session.path'), Config::get('session.domain'), Config::get('session.https')); } diff --git a/system/session/driver/db.php b/system/session/driver/db.php index 49f4245f..84c48200 100644 --- a/system/session/driver/db.php +++ b/system/session/driver/db.php @@ -10,14 +10,8 @@ class DB implements \System\Session\Driver { */ public function load($id) { - // ----------------------------------------------------- - // Find the session in the database. - // ----------------------------------------------------- $session = $this->query()->find($id); - // ----------------------------------------------------- - // If the session was found, return it. - // ----------------------------------------------------- if ( ! is_null($session)) { return array('id' => $session->id, 'last_activity' => $session->last_activity, 'data' => unserialize($session->data)); @@ -32,14 +26,7 @@ public function load($id) */ public function save($session) { - // ----------------------------------------------------- - // Delete the existing session row. - // ----------------------------------------------------- $this->delete($session['id']); - - // ----------------------------------------------------- - // Insert a new session row. - // ----------------------------------------------------- $this->query()->insert(array('id' => $session['id'], 'last_activity' => $session['last_activity'], 'data' => serialize($session['data']))); } diff --git a/system/session/driver/file.php b/system/session/driver/file.php index 840a5483..d59f4258 100644 --- a/system/session/driver/file.php +++ b/system/session/driver/file.php @@ -10,9 +10,6 @@ class File implements \System\Session\Driver { */ public function load($id) { - // ----------------------------------------------------- - // Look for the session on the file system. - // ----------------------------------------------------- if (file_exists($path = APP_PATH.'sessions/'.$id)) { return unserialize(file_get_contents($path)); @@ -51,9 +48,6 @@ public function sweep($expiration) { foreach (glob(APP_PATH.'sessions/*') as $file) { - // ----------------------------------------------------- - // If the session file has expired, delete it. - // ----------------------------------------------------- if (filetype($file) == 'file' and filemtime($file) < $expiration) { @unlink($file); diff --git a/system/str.php b/system/str.php index 36d864dc..5a0415eb 100644 --- a/system/str.php +++ b/system/str.php @@ -61,19 +61,10 @@ public static function title($value) */ public static function random($length = 16) { - // ----------------------------------------------------- - // Split the character pool into an array. - // ----------------------------------------------------- $pool = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 1); - // ----------------------------------------------------- - // Initialize the return value. - // ----------------------------------------------------- $value = ''; - // ----------------------------------------------------- - // Build the random string. - // ----------------------------------------------------- for ($i = 0; $i < $length; $i++) { $value .= $pool[mt_rand(0, 61)]; diff --git a/system/test.php b/system/test.php new file mode 100644 index 00000000..36cecd1c --- /dev/null +++ b/system/test.php @@ -0,0 +1,65 @@ + $test) + { + if ( ! is_callable($test)) + { + throw new \Exception("Test [$name] in suite [$suite] is not callable."); + } + + static::$passed = ($result = call_user_func($test)) ? static::$passed + 1 : static::$passed; + static::$results[$suite][] = array('name' => $name, 'result' => $result); + } + } + + /** + * Get the test report view. + * + * @return View + */ + public static function report() + { + return View::make('test/report') + ->bind('results', static::$results) + ->bind('passed', static::$passed) + ->bind('total', static::$total); + } + +} \ No newline at end of file diff --git a/system/tests/.gitignore b/system/tests/.gitignore new file mode 100644 index 00000000..e69de29b diff --git a/system/text.php b/system/text.php index f527d57c..6a06a92b 100644 --- a/system/text.php +++ b/system/text.php @@ -12,9 +12,6 @@ class Text { */ public static function words($value, $limit, $end = '…') { - // ----------------------------------------------------- - // If the value is an empty string, bail out. - // ----------------------------------------------------- if (trim($value) == '') { return $value; @@ -34,9 +31,6 @@ public static function words($value, $limit, $end = '…') $end = ''; } - // ----------------------------------------------------- - // Add the ending character to the string. - // ----------------------------------------------------- return rtrim($matches[0]).$end; } @@ -50,9 +44,6 @@ public static function words($value, $limit, $end = '…') */ public static function characters($value, $limit, $end = '…') { - // ----------------------------------------------------- - // If the value does not exceed the limit, bail out. - // ----------------------------------------------------- if (strlen($value) < $limit) { return $value; @@ -63,17 +54,11 @@ public static function characters($value, $limit, $end = '…') // ----------------------------------------------------- $value = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $value)); - // ----------------------------------------------------- - // If the value does not exceed the limit, bail out. - // ----------------------------------------------------- if (strlen($value) <= $limit) { return $value; } - // ----------------------------------------------------- - // Initialize the output string. - // ----------------------------------------------------- $out = ''; // ----------------------------------------------------- @@ -82,24 +67,12 @@ public static function characters($value, $limit, $end = '…') // ----------------------------------------------------- foreach (explode(' ', trim($value)) as $val) { - // ----------------------------------------------------- - // Add the word to the output. - // ----------------------------------------------------- $out .= $val.' '; - // ----------------------------------------------------- - // Check the output length. - // ----------------------------------------------------- if (strlen($out) >= $limit) { - // ----------------------------------------------------- - // Trim the output. - // ----------------------------------------------------- $out = trim($out); - // ----------------------------------------------------- - // Add the ending character to the string. - // ----------------------------------------------------- return (strlen($out) == strlen($value)) ? $out : $out.$end; } } @@ -115,9 +88,6 @@ public static function characters($value, $limit, $end = '…') */ public static function censor($value, $censored, $replacement = '####') { - // ----------------------------------------------------- - // Pad the value with spaces. - // ----------------------------------------------------- $value = ' '.$value.' '; // ----------------------------------------------------- diff --git a/system/url.php b/system/url.php index 46fdc030..22ac9701 100644 --- a/system/url.php +++ b/system/url.php @@ -18,9 +18,6 @@ public static function to($url = '', $https = false) return $url; } - // ---------------------------------------------------- - // Get the base URL of the application. - // ---------------------------------------------------- $base = Config::get('application.url'); // ---------------------------------------------------- @@ -55,9 +52,6 @@ public static function to_secure($url = '') */ public static function to_route($name, $parameters = array(), $https = false) { - // ---------------------------------------------------- - // Does the named route exist? - // ---------------------------------------------------- if ( ! is_null($route = Router::find($name))) { $uris = explode(', ', key($route)); diff --git a/system/view.php b/system/view.php index 4ef22dc6..d4d6de5e 100644 --- a/system/view.php +++ b/system/view.php @@ -41,10 +41,6 @@ public function __construct($view, $data = array()) { $this->view = $view; $this->data = $data; - - // ----------------------------------------------------- - // Get the contents of the view from the file system. - // ----------------------------------------------------- $this->content = $this->load($view); } @@ -68,23 +64,14 @@ public static function make($view, $data = array()) */ private function load($view) { - // ----------------------------------------------------- - // Is the view in the application directory? - // ----------------------------------------------------- if (file_exists($path = APP_PATH.'views/'.$view.EXT)) { return file_get_contents($path); } - // ----------------------------------------------------- - // Is the view in the system directory? - // ----------------------------------------------------- elseif (file_exists($path = SYS_PATH.'views/'.$view.EXT)) { return file_get_contents($path); } - // ----------------------------------------------------- - // Could not locate the view... bail out. - // ----------------------------------------------------- else { throw new \Exception("View [$view] doesn't exist."); @@ -111,9 +98,6 @@ public function bind($key, $value) */ public function get() { - // ----------------------------------------------------- - // Set the name of the last rendered view. - // ----------------------------------------------------- static::$last = $this->view; // ----------------------------------------------------- @@ -127,24 +111,12 @@ public function get() } } - // ----------------------------------------------------- - // Extract the view data into the local scope. - // ----------------------------------------------------- extract($this->data, EXTR_SKIP); - // ----------------------------------------------------- - // Start an output buffer to catch the content. - // ----------------------------------------------------- ob_start(); - // ----------------------------------------------------- - // Echo the content of the view. - // ----------------------------------------------------- echo eval('?>'.$this->content); - // ----------------------------------------------------- - // Get the contents of the output buffer. - // ----------------------------------------------------- return ob_get_clean(); } diff --git a/system/views/error/exception.php b/system/views/error/exception.php index f06f5f81..996eecf9 100644 --- a/system/views/error/exception.php +++ b/system/views/error/exception.php @@ -20,6 +20,7 @@ font-size: 45px; color: #6d6d6d; margin: 0 0 10px 0; + text-shadow: 1px 1px #000; } h3 { diff --git a/system/views/test/report.php b/system/views/test/report.php new file mode 100644 index 00000000..ab781a22 --- /dev/null +++ b/system/views/test/report.php @@ -0,0 +1,80 @@ + + + + + Laravel - Test Report + + + + + + +
    +

    Test Report

    + +

    Passed / Tests

    + + $results): ?> +

    + + + +
    + : +
    + + + +
    + + \ No newline at end of file