From a7de97e74cbfe21cd2606c2253134a3bc8dda1f7 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Sat, 31 Dec 2011 18:41:08 +0000 Subject: Added method chaining to DBForge. --- system/database/DB_forge.php | 49 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'system/database') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 78bf77a9f..c74fa4068 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -102,12 +102,11 @@ class CI_DB_forge { /** * Add Key * - * @access public * @param string key * @param string type - * @return void + * @return object */ - function add_key($key = '', $primary = FALSE) + public function add_key($key = '', $primary = FALSE) { if (is_array($key)) { @@ -132,6 +131,8 @@ class CI_DB_forge { { $this->keys[] = $key; } + + return $this; } // -------------------------------------------------------------------- @@ -139,11 +140,10 @@ class CI_DB_forge { /** * Add Field * - * @access public * @param string collation - * @return void + * @return object */ - function add_field($field = '') + public function add_field($field = '') { if ($field == '') { @@ -155,12 +155,12 @@ class CI_DB_forge { if ($field == 'id') { $this->add_field(array( - 'id' => array( - 'type' => 'INT', - 'constraint' => 9, - 'auto_increment' => TRUE - ) - )); + 'id' => array( + 'type' => 'INT', + 'constraint' => 9, + 'auto_increment' => TRUE + ) + )); $this->add_key('id', TRUE); } else @@ -178,7 +178,8 @@ class CI_DB_forge { { $this->fields = array_merge($this->fields, $field); } - + + return $this; } // -------------------------------------------------------------------- @@ -186,11 +187,10 @@ class CI_DB_forge { /** * Create Table * - * @access public * @param string the table name * @return bool */ - function create_table($table = '', $if_not_exists = FALSE) + public function create_table($table = '', $if_not_exists = FALSE) { if ($table == '') { @@ -219,11 +219,10 @@ class CI_DB_forge { /** * Drop Table * - * @access public * @param string the table name * @return bool */ - function drop_table($table_name) + public function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); @@ -240,12 +239,11 @@ class CI_DB_forge { /** * Rename Table * - * @access public * @param string the old table name * @param string the new table name * @return bool */ - function rename_table($table_name, $new_table_name) + public function rename_table($table_name, $new_table_name) { if ($table_name == '' OR $new_table_name == '') { @@ -261,13 +259,12 @@ class CI_DB_forge { /** * Column Add * - * @access public * @param string the table name * @param string the column name * @param string the column definition * @return bool */ - function add_column($table = '', $field = array(), $after_field = '') + public function add_column($table = '', $field = array(), $after_field = '') { if ($table == '') { @@ -297,7 +294,6 @@ class CI_DB_forge { } return TRUE; - } // -------------------------------------------------------------------- @@ -305,12 +301,11 @@ class CI_DB_forge { /** * Column Drop * - * @access public * @param string the table name * @param string the column name * @return bool */ - function drop_column($table = '', $column_name = '') + public function drop_column($table = '', $column_name = '') { if ($table == '') @@ -333,13 +328,12 @@ class CI_DB_forge { /** * Column Modify * - * @access public * @param string the table name * @param string the column name * @param string the column definition * @return bool */ - function modify_column($table = '', $field = array()) + public function modify_column($table = '', $field = array()) { if ($table == '') { @@ -384,10 +378,9 @@ class CI_DB_forge { * * Resets table creation vars * - * @access private * @return void */ - function _reset() + protected function _reset() { $this->fields = array(); $this->keys = array(); -- cgit v1.2.3-24-g4f1b