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 = '