From ef112c0830df4a31563351125888b0d522a1c965 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 7 Feb 2011 13:01:47 +0000 Subject: Added decimal, less_than and greater_than rules to the Form validation Class. --- system/libraries/Form_validation.php | 70 ++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index fc5b82ee3..745fb7c03 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -138,14 +138,14 @@ class CI_Form_validation { // Build our master array $this->_field_data[$field] = array( - 'field' => $field, - 'label' => $label, - 'rules' => $rules, - 'is_array' => $is_array, - 'keys' => $indexes, - 'postdata' => NULL, - 'error' => '' - ); + 'field' => $field, + 'label' => $label, + 'rules' => $rules, + 'is_array' => $is_array, + 'keys' => $indexes, + 'postdata' => NULL, + 'error' => '' + ); return $this; } @@ -1147,7 +1147,57 @@ class CI_Form_validation { */ function integer($str) { - return (bool)preg_match( '/^[\-+]?[0-9]+$/', $str); + return (bool) preg_match('/^[\-+]?[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Decimal number + * + * @access public + * @param string + * @return bool + */ + function decimal($str) + { + return (bool) preg_match('/^[\-+]?[0-9]+\.[0-9]+$/', $str); + } + + // -------------------------------------------------------------------- + + /** + * Greather than + * + * @access public + * @param string + * @return bool + */ + function greater_than($str, $min) + { + if ( ! is_numeric($str)) + { + return false; + } + return $str > $min; + } + + // -------------------------------------------------------------------- + + /** + * Less than + * + * @access public + * @param string + * @return bool + */ + function less_than($str, $max) + { + if ( ! is_numeric($str)) + { + return false; + } + return $str < $max; } // -------------------------------------------------------------------- @@ -1161,7 +1211,7 @@ class CI_Form_validation { */ function is_natural($str) { - return (bool)preg_match( '/^[0-9]+$/', $str); + return (bool) preg_match( '/^[0-9]+$/', $str); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 9758d84b69185f80fd8197f28046af7ef3b2a2d3 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 7 Feb 2011 20:39:00 +0000 Subject: Added Migrations library, config and an example controller/migration file. --- system/libraries/Migration.php | 336 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 system/libraries/Migration.php (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php new file mode 100644 index 000000000..73c55c346 --- /dev/null +++ b/system/libraries/Migration.php @@ -0,0 +1,336 @@ + $val) + { + $this->{'_' . $key} = $val; + } + + log_message('debug', 'Migrations class initialized'); + + // Are they trying to use migrations while it is disabled? + if ($this->_migration_enabled !== TRUE) + { + show_error('Migrations has been loaded but is disabled or set up incorrectly.'); + } + + // If not set, set it + $this->_migration_path == '' OR $this->_migration_path = APPPATH . 'migrations/'; + + // Add trailing slash if not set + $this->_migration_path = rtrim($this->_migration_path, '/').'/'; + + // They'll probably be using dbforge + $this->load->dbforge(); + + // If the migrations table is missing, make it + if ( ! $this->db->table_exists('migrations')) + { + $this->dbforge->add_field(array( + 'version' => array('type' => 'INT', 'constraint' => 3), + )); + + $this->dbforge->create_table('migrations', TRUE); + + $this->db->insert('migrations', array('version' => 0)); + } + } + + // -------------------------------------------------------------------- + + /** + * Migrate to a schema version + * + * Calls each migration step required to get to the schema version of + * choice + * + * @access public + * @param $version integer Target schema version + * @return mixed TRUE if already latest, FALSE if failed, int if upgraded + */ + function version($target_version) + { + $start = $current_version = $this->_get_version(); + $stop = $target_version; + + if ($target_version > $current_version) + { + // Moving Up + ++$start; + ++$stop; + $step = 1; + } + + else + { + // Moving Down + $step = -1; + } + + $method = $step === 1 ? 'up' : 'down'; + $migrations = array(); + + // We now prepare to actually DO the migrations + // But first let's make sure that everything is the way it should be + for ($i = $start; $i != $stop; $i += $step) + { + $f = glob(sprintf($this->_migration_path . '%03d_*.php', $i)); + + // Only one migration per step is permitted + if (count($f) > 1) + { + $this->error = sprintf($this->lang->line('multiple_migration_version'), $i); + return FALSE; + } + + // Migration step not found + if (count($f) == 0) + { + // If trying to migrate up to a version greater than the last + // existing one, migrate to the last one. + if ($step == 1) + { + break; + } + + // If trying to migrate down but we're missing a step, + // something must definitely be wrong. + $this->error = sprintf($this->lang->line('migration_not_found'), $i); + return FALSE; + } + + $file = basename($f[0]); + $name = basename($f[0], '.php'); + + // Filename validations + if (preg_match('/^\d{3}_(\w+)$/', $name, $match)) + { + $match[1] = strtolower($match[1]); + + // Cannot repeat a migration at different steps + if (in_array($match[1], $migrations)) + { + $this->error = sprintf($this->lang->line('multiple_migrations_name'), $match[1]); + return FALSE; + } + + include $f[0]; + $class = 'Migration_' . ucfirst($match[1]); + + if ( ! class_exists($class)) + { + $this->error = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); + return FALSE; + } + + if ( ! is_callable(array($class, 'up')) || ! is_callable(array($class, 'down'))) + { + $this->error = sprintf($this->lang->line('wrong_migration_interface'), $class); + return FALSE; + } + + $migrations[] = $match[1]; + } + else + { + $this->error = sprintf($this->lang->line('invalid_migration_filename'), $file); + return FALSE; + } + } + + $this->log('Current schema version: ' . $current_version); + + $version = $i + ($step == 1 ? -1 : 0); + + // If there is nothing to do so quit + if ($migrations === array()) + { + return TRUE; + } + + $this->log('Moving ' . $method . ' to version ' . $version); + + // Loop through the migrations + foreach ($migrations AS $migration) + { + // Run the migration class + $class = 'Migration_' . ucfirst(strtolower($migration)); + call_user_func(array(new $class, $method)); + + $current_version += $step; + $this->_update_version($current_version); + } + + $this->log('All done. Schema is at version '.$current_version); + + return $current_version; + } + + // -------------------------------------------------------------------- + + /** + * Set's the schema to the latest migration + * + * @access public + * @return mixed true if already latest, false if failed, int if upgraded + */ + public function latest() + { + if ( ! $migrations = $this->find_migrations()) + { + throw new Exception('no_migrations_found'); + return false; + } + + $last_migration = basename(end($migrations)); + + // Calculate the last migration step from existing migration + // filenames and procceed to the standard version migration + $last_version = intval(substr($last_migration, 0, 3)); + return $this->version($last_version); + } + + // -------------------------------------------------------------------- + + /** + * Set's the schema to the migration version set in config + * + * @access public + * @return mixed true if already current, false if failed, int if upgraded + */ + public function current() + { + $version = $this->_migration_version; + return $this->version($version); + } + + // -------------------------------------------------------------------- + + /** + * Set's the schema to the latest migration + * + * @access public + * @return mixed true if already latest, false if failed, int if upgraded + */ + + protected static function find_migrations() + { + // Load all *_*.php files in the migrations path + $files = glob($this->_migration_path . '*_*.php'); + $file_count = count($files); + + for ($i = 0; $i < $file_count; $i++) + { + // Mark wrongly formatted files as false for later filtering + $name = basename($files[$i], '.php'); + if ( ! preg_match('/^\d{3}_(\w+)$/', $name)) + { + $files[$i] = FALSE; + } + } + + sort($files); + + return $files; + } + + // -------------------------------------------------------------------- + + /** + * Retrieves current schema version + * + * @access private + * @return integer Current Schema version + */ + private function _get_version() + { + $row = $this->db->get('migrations')->row(); + return $row ? $row->version : 0; + } + + // -------------------------------------------------------------------- + + /** + * Stores the current schema version + * + * @access private + * @param $migrations integer Schema version reached + * @return void Outputs a report of the migration + */ + private function _update_version($migrations) + { + return $this->db->update('migrations', array( + 'version' => $migrations + )); + } + + // -------------------------------------------------------------------- + + /** + * Stores the current schema version + * + * @access private + * @param $migrations integer Schema version reached + * @return void Outputs a report of the migration + */ + private function log($text) + { + echo $text.'
'; + } + + // -------------------------------------------------------------------- + + /** + * Enable the use of CI super-global + * + * @access public + * @param $var + * @return mixed + */ + public function __get($var) + { + return get_instance()->$var; + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3167eebb81d740e0a74b28ff0353dd4fcf110d0e Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Tue, 8 Feb 2011 21:19:28 +0000 Subject: MySQL Driver will now wrap field names for insert(), update() and replace() with backticks (`) so fields like "default" and "order" will not cause SQL errors. --- system/database/drivers/mysql/mysql_driver.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index df18c912e..c9fc1ecab 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -287,12 +287,12 @@ class CI_DB_mysql_driver extends CI_DB { if (is_array($str)) { foreach($str as $key => $val) - { + { $str[$key] = $this->escape_str($val, $like); - } + } - return $str; - } + return $str; + } if (function_exists('mysql_real_escape_string') AND is_resource($this->conn_id)) { @@ -532,7 +532,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; + return "REPLACE INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -569,7 +569,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); + return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES ".implode(', ', $values); } // -------------------------------------------------------------------- @@ -592,7 +592,7 @@ class CI_DB_mysql_driver extends CI_DB { { foreach($values as $key => $val) { - $valstr[] = $key." = ".$val; + $valstr[] = sprintf('`%s` = %s', $key, $val); } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; -- cgit v1.2.3-24-g4f1b From a12216baff3aef18413a84e3d37aba2096b5ebe8 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 9 Feb 2011 16:09:31 +0000 Subject: Reverted recent MySQL backtick escaping as some queries were double-escaping. --- system/database/drivers/mysql/mysql_driver.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index c9fc1ecab..72c834b8f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -532,7 +532,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert($table, $keys, $values) { - return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -551,7 +551,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _replace($table, $keys, $values) { - return "REPLACE INTO ".$table." (`".implode('`, `', $keys)."`) VALUES (".implode(', ', $values).")"; + return "REPLACE INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")"; } // -------------------------------------------------------------------- @@ -569,7 +569,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _insert_batch($table, $keys, $values) { - return "INSERT INTO ".$table." (`".implode('`, `', $keys)."`) VALUES ".implode(', ', $values); + return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES ".implode(', ', $values); } // -------------------------------------------------------------------- @@ -592,7 +592,7 @@ class CI_DB_mysql_driver extends CI_DB { { foreach($values as $key => $val) { - $valstr[] = sprintf('`%s` = %s', $key, $val); + $valstr[] = $key . ' = ' . $val; } $limit = ( ! $limit) ? '' : ' LIMIT '.$limit; -- cgit v1.2.3-24-g4f1b From 23351dc30a1787d30a97dd0a8ba83d6e312a5a2f Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Mon, 14 Feb 2011 00:14:21 -0600 Subject: Fix #329 where the file caching driver referenced the incorrect cache directory. --- system/libraries/Cache/drivers/Cache_file.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Cache/drivers/Cache_file.php b/system/libraries/Cache/drivers/Cache_file.php index 3ed357f2f..86d1a3b6a 100644 --- a/system/libraries/Cache/drivers/Cache_file.php +++ b/system/libraries/Cache/drivers/Cache_file.php @@ -39,7 +39,7 @@ class Cache_file extends CI_Driver { $path = $CI->config->item('cache_path'); - $this->_cache_path = ($path == '') ? BASEPATH.'cache/' : $path; + $this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 8761ef56b465a190489ed555c6a0ab58470bfc73 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:13:52 -0500 Subject: Uppercasing some stray lowercase keywords for code consistency --- system/database/drivers/odbc/odbc_result.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 10 +++++----- system/libraries/Form_validation.php | 4 ++-- system/libraries/Image_lib.php | 2 +- system/libraries/Xmlrpc.php | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'system') diff --git a/system/database/drivers/odbc/odbc_result.php b/system/database/drivers/odbc/odbc_result.php index a81a2b8b7..5d64a464f 100644 --- a/system/database/drivers/odbc/odbc_result.php +++ b/system/database/drivers/odbc/odbc_result.php @@ -188,7 +188,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _odbc_fetch_object(& $odbc_result) { $rs = array(); - $rs_obj = false; + $rs_obj = FALSE; if (odbc_fetch_into($odbc_result, $rs)) { foreach ($rs as $k=>$v) { $field_name= odbc_field_name($odbc_result, $k+1); @@ -210,7 +210,7 @@ class CI_DB_odbc_result extends CI_DB_result { */ function _odbc_fetch_array(& $odbc_result) { $rs = array(); - $rs_assoc = false; + $rs_assoc = FALSE; if (odbc_fetch_into($odbc_result, $rs)) { $rs_assoc=array(); foreach ($rs as $k=>$v) { diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 0bb7974d8..81ca6e051 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -330,21 +330,21 @@ class CI_DB_postgre_driver extends CI_DB { $v = $this->_version(); $v = $v['server']; - $table = func_num_args() > 0 ? func_get_arg(0) : null; - $column = func_num_args() > 1 ? func_get_arg(1) : null; + $table = func_num_args() > 0 ? func_get_arg(0) : NULL; + $column = func_num_args() > 1 ? func_get_arg(1) : NULL; - if ($table == null && $v >= '8.1') + if ($table == NULL && $v >= '8.1') { $sql='SELECT LASTVAL() as ins_id'; } - elseif ($table != null && $column != null && $v >= '8.0') + elseif ($table != NULL && $column != NULL && $v >= '8.0') { $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column); $query = $this->query($sql); $row = $query->row(); $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq); } - elseif ($table != null) + elseif ($table != NULL) { // seq_name passed in table parameter $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table); diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 745fb7c03..c6d7c2976 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1177,7 +1177,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str > $min; } @@ -1195,7 +1195,7 @@ class CI_Form_validation { { if ( ! is_numeric($str)) { - return false; + return FALSE; } return $str < $max; } diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 41f9ad393..8902f524d 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -749,7 +749,7 @@ class CI_Image_lib { @chmod($this->full_dst_path, FILE_WRITE_MODE); - return true; + return TRUE; } // -------------------------------------------------------------------- diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 9cf307cc0..0d5a261f9 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -358,7 +358,7 @@ class XML_RPC_Client extends CI_Xmlrpc var $errno = ''; var $errstring = ''; var $timeout = 5; - var $no_multicall = false; + var $no_multicall = FALSE; public function __construct($path, $server, $port=80) { @@ -896,7 +896,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['isf'] = 1; break; case 'PARAM': - $this->xh[$the_parser]['value'] = null; + $this->xh[$the_parser]['value'] = NULL; break; case 'VALUE': $this->xh[$the_parser]['vt'] = 'value'; @@ -925,7 +925,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['valuestack'][0]['name'] = ''; // Set NULL value to check to see if value passed for this param/member - $this->xh[$the_parser]['value'] = null; + $this->xh[$the_parser]['value'] = NULL; break; case 'DATA': case 'METHODCALL': -- cgit v1.2.3-24-g4f1b From 45e3cdf52d7438c5a6adf70835d96cfeab1eea0e Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:26:20 -0500 Subject: Whitespace cleanup for code consistency --- system/helpers/captcha_helper.php | 2 +- system/helpers/file_helper.php | 2 +- system/helpers/language_helper.php | 2 +- system/helpers/number_helper.php | 2 +- system/helpers/smiley_helper.php | 4 ++-- system/helpers/text_helper.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index c0e3798f4..19ec0c778 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -87,7 +87,7 @@ if ( ! function_exists('create_captcha')) $current_dir = @opendir($img_path); - while($filename = @readdir($current_dir)) + while ($filename = @readdir($current_dir)) { if ($filename != "." and $filename != ".." and $filename != "index.html") { diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 334eef87c..9518e4843 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -128,7 +128,7 @@ if ( ! function_exists('delete_files')) return FALSE; } - while(FALSE !== ($filename = @readdir($current_dir))) + while (FALSE !== ($filename = @readdir($current_dir))) { if ($filename != "." and $filename != "..") { diff --git a/system/helpers/language_helper.php b/system/helpers/language_helper.php index 68c1a1fc6..ac0d69da1 100644 --- a/system/helpers/language_helper.php +++ b/system/helpers/language_helper.php @@ -1,4 +1,4 @@ - $id) + foreach ($alias as $name => $id) { $m[] = '"'.$name.'" : "'.$id.'"'; } @@ -101,7 +101,7 @@ EOF; { if (is_array($alias)) { - foreach($alias as $name => $id) + foreach ($alias as $name => $id) { $r .= 'smiley_map["'.$name.'"] = "'.$id.'";'."\n"; } diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 47e6ccc93..96afd4cee 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -443,7 +443,7 @@ if ( ! function_exists('word_wrap')) } $temp = ''; - while((strlen($line)) > $charlim) + while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) -- cgit v1.2.3-24-g4f1b From 5d5895fd1084cd62721afd4c5f875eb2f99eefc4 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:27:07 -0500 Subject: Whitespace cleanup in core/ --- system/core/Config.php | 4 ++-- system/core/Input.php | 6 +++--- system/core/Loader.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/core/Config.php b/system/core/Config.php index da22222dc..75f945efd 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -51,7 +51,7 @@ class CI_Config { // Set the base_url automatically if none was provided if ($this->config['base_url'] == '') { - if(isset($_SERVER['HTTP_HOST'])) + if (isset($_SERVER['HTTP_HOST'])) { $base_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http'; $base_url .= '://'. $_SERVER['HTTP_HOST']; @@ -83,7 +83,7 @@ class CI_Config { $file = ($file == '') ? 'config' : str_replace(EXT, '', $file); $loaded = FALSE; - foreach($this->_config_paths as $path) + foreach ($this->_config_paths as $path) { $file_path = $path.'config/'.ENVIRONMENT.'/'.$file.EXT; diff --git a/system/core/Input.php b/system/core/Input.php index 3e82874fd..cb842812f 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -413,7 +413,7 @@ class CI_Input { { if (is_array($_GET) AND count($_GET) > 0) { - foreach($_GET as $key => $val) + foreach ($_GET as $key => $val) { $_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } @@ -423,7 +423,7 @@ class CI_Input { // Clean $_POST Data if (is_array($_POST) AND count($_POST) > 0) { - foreach($_POST as $key => $val) + foreach ($_POST as $key => $val) { $_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } @@ -441,7 +441,7 @@ class CI_Input { unset($_COOKIE['$Path']); unset($_COOKIE['$Domain']); - foreach($_COOKIE as $key => $val) + foreach ($_COOKIE as $key => $val) { $_COOKIE[$this->_clean_input_keys($key)] = $this->_clean_input_data($val); } diff --git a/system/core/Loader.php b/system/core/Loader.php index ca2f016e7..7003318ee 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -79,7 +79,7 @@ class CI_Loader { { if (is_array($library)) { - foreach($library as $read) + foreach ($library as $read) { $this->library($read); } @@ -127,7 +127,7 @@ class CI_Loader { { if (is_array($model)) { - foreach($model as $babe) + foreach ($model as $babe) { $this->model($babe); } -- cgit v1.2.3-24-g4f1b From 68d29873fb155651f46523fdcfb9027102a89f1f Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:39:06 -0500 Subject: Large cleanup of xmlrpcs docblocks. --- system/libraries/Xmlrpcs.php | 178 ++++++++++++++++++++++++++++++------------- 1 file changed, 123 insertions(+), 55 deletions(-) (limited to 'system') diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 6bedfe324..9cd332147 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -59,10 +59,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc log_message('debug', "XML-RPC Server Class Initialized"); } - //------------------------------------- - // Initialize Prefs and Serve - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Initialize Prefs and Serve + * + * @access public + * @param mixed + * @return void + */ function initialize($config=array()) { if (isset($config['functions']) && is_array($config['functions'])) @@ -86,11 +91,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc } } - //------------------------------------- - // Setting of System Methods - //------------------------------------- + // -------------------------------------------------------------------- - function set_system_methods () + /** + * Setting of System Methods + * + * @access public + * @return void + */ + function set_system_methods() { $this->methods = array( 'system.listMethods' => array( @@ -112,11 +121,14 @@ class CI_Xmlrpcs extends CI_Xmlrpc ); } + // -------------------------------------------------------------------- - //------------------------------------- - // Main Server Function - //------------------------------------- - + /** + * Main Server Function + * + * @access public + * @return void + */ function serve() { $r = $this->parseRequest(); @@ -129,11 +141,19 @@ class CI_Xmlrpcs extends CI_Xmlrpc exit($payload); } - //------------------------------------- - // Add Method to Class - //------------------------------------- + // -------------------------------------------------------------------- - function add_to_map($methodname,$function,$sig,$doc) + /** + * Add Method to Class + * + * @access public + * @param string method name + * @param string function + * @param string signature + * @param string docstring + * @return void + */ + function add_to_map($methodname, $function, $sig, $doc) { $this->methods[$methodname] = array( 'function' => $function, @@ -142,11 +162,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc ); } + // -------------------------------------------------------------------- - //------------------------------------- - // Parse Server Request - //------------------------------------- - + /** + * Parse Server Request + * + * @access public + * @param string data + * @return object xmlrpc response + */ function parseRequest($data='') { global $HTTP_RAW_POST_DATA; @@ -196,7 +220,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc xml_get_current_line_number($parser))); xml_parser_free($parser); } - elseif($parser_object->xh[$parser]['isf']) + elseif ($parser_object->xh[$parser]['isf']) { return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); } @@ -207,7 +231,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($parser_object->xh[$parser]['method']); $plist=''; - for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) + for ($i=0; $i < count($parser_object->xh[$parser]['params']); $i++) { if ($this->debug === TRUE) { @@ -239,10 +263,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc return $r; } - //------------------------------------- - // Executes the Method - //------------------------------------- + // -------------------------------------------------------------------- + /** + * Executes the Method + * + * @access protected + * @param object + * @return mixed + */ function _execute($m) { $methName = $m->method_name; @@ -297,13 +326,13 @@ class CI_Xmlrpcs extends CI_Xmlrpc if (isset($this->methods[$methName]['signature'])) { $sig = $this->methods[$methName]['signature']; - for($i=0; $iparams)+1) { - for($n=0; $n < count($m->params); $n++) + for ($n=0; $n < count($m->params); $n++) { $p = $m->params[$n]; $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf(); @@ -352,23 +381,27 @@ class CI_Xmlrpcs extends CI_Xmlrpc return call_user_func($this->methods[$methName]['function'], $m); } } + + // -------------------------------------------------------------------- - - //------------------------------------- - // Server Function: List Methods - //------------------------------------- - + /** + * Server Function: List Methods + * + * @access public + * @param mixed + * @return object + */ function listMethods($m) { $v = new XML_RPC_Values(); $output = array(); - foreach($this->methods as $key => $value) + foreach ($this->methods as $key => $value) { $output[] = new XML_RPC_Values($key, 'string'); } - foreach($this->system_methods as $key => $value) + foreach ($this->system_methods as $key => $value) { $output[]= new XML_RPC_Values($key, 'string'); } @@ -376,11 +409,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc $v->addArray($output); return new XML_RPC_Response($v); } + + // -------------------------------------------------------------------- - //------------------------------------- - // Server Function: Return Signature for Method - //------------------------------------- - + /** + * Server Function: Return Signature for Method + * + * @access public + * @param mixed + * @return object + */ function methodSignature($m) { $parameters = $m->output_parameters(); @@ -393,11 +431,11 @@ class CI_Xmlrpcs extends CI_Xmlrpc $sigs = array(); $signature = $this->methods[$method_name]['signature']; - for($i=0; $i < count($signature); $i++) + for ($i=0; $i < count($signature); $i++) { $cursig = array(); $inSig = $signature[$i]; - for($j=0; $joutput_parameters(); @@ -437,11 +480,16 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); } } + + // -------------------------------------------------------------------- - //------------------------------------- - // Server Function: Multi-call - //------------------------------------- - + /** + * Server Function: Multi-call + * + * @access public + * @param mixed + * @return object + */ function multicall($m) { // Disabled @@ -459,7 +507,7 @@ class CI_Xmlrpcs extends CI_Xmlrpc $m = new XML_RPC_Message($value[0]); $plist=''; - for($i=0; $i < count($value[1]); $i++) + for ($i=0; $i < count($value[1]); $i++) { $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); } @@ -477,11 +525,15 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); } + // -------------------------------------------------------------------- - //------------------------------------- - // Multi-call Function: Error Handling - //------------------------------------- - + /** + * Multi-call Function: Error Handling + * + * @access public + * @param mixed + * @return object + */ function multicall_error($err) { $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); @@ -493,29 +545,45 @@ class CI_Xmlrpcs extends CI_Xmlrpc return new XML_RPC_Values($struct, 'struct'); } + // -------------------------------------------------------------------- - //------------------------------------- - // Multi-call Function: Processes method - //------------------------------------- - + /** + * Multi-call Function: Processes method + * + * @access public + * @param mixed + * @return object + */ function do_multicall($call) { if ($call->kindOf() != 'struct') + { return $this->multicall_error('notstruct'); + } elseif ( ! $methName = $call->me['struct']['methodName']) + { return $this->multicall_error('nomethod'); + } list($scalar_type,$scalar_value)=each($methName->me); $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string') + { return $this->multicall_error('notstring'); + } elseif ($scalar_value == 'system.multicall') + { return $this->multicall_error('recursion'); + } elseif ( ! $params = $call->me['struct']['params']) + { return $this->multicall_error('noparams'); + } elseif ($params->kindOf() != 'array') + { return $this->multicall_error('notarray'); + } list($a,$b)=each($params->me); $numParams = count($b); -- cgit v1.2.3-24-g4f1b From 14287f3e81d4d717ff49e640d799c579e593f0c0 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:39:34 -0500 Subject: Whitespace cleanup in libraries/ --- system/libraries/Driver.php | 6 ++--- system/libraries/Email.php | 12 +++++----- system/libraries/Form_validation.php | 2 +- system/libraries/Profiler.php | 4 ++-- system/libraries/Security.php | 2 +- system/libraries/Sha1.php | 2 +- system/libraries/Table.php | 8 +++---- system/libraries/Trackback.php | 4 ++-- system/libraries/Upload.php | 2 +- system/libraries/Xmlrpc.php | 46 +++++++++++++++++------------------- system/libraries/Zip.php | 2 +- 11 files changed, 44 insertions(+), 46 deletions(-) (limited to 'system') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 15fc3da26..02e093d7e 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -1,4 +1,4 @@ -lib_name)) + if ( ! isset($this->lib_name)) { $this->lib_name = get_class($this); } @@ -143,7 +143,7 @@ class CI_Driver { } } - foreach($r->getProperties() as $prop) + foreach ($r->getProperties() as $prop) { if ($prop->isPublic()) { diff --git a/system/libraries/Email.php b/system/libraries/Email.php index e5af38f45..6c21f114d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -897,7 +897,7 @@ class CI_Email { } $temp = ''; - while((strlen($line)) > $charlim) + while ((strlen($line)) > $charlim) { // If the over-length word is a URL we won't wrap it if (preg_match("!\[url.+\]|://|wwww.!", $line)) @@ -973,7 +973,7 @@ class CI_Email { reset($this->_headers); $this->_header_str = ""; - foreach($this->_headers as $key => $val) + foreach ($this->_headers as $key => $val) { $val = trim($val); @@ -1607,14 +1607,14 @@ class CI_Email { $this->_send_command('from', $this->clean_email($this->_headers['From'])); - foreach($this->_recipients as $val) + foreach ($this->_recipients as $val) { $this->_send_command('to', $val); } if (count($this->_cc_array) > 0) { - foreach($this->_cc_array as $val) + foreach ($this->_cc_array as $val) { if ($val != "") { @@ -1625,7 +1625,7 @@ class CI_Email { if (count($this->_bcc_array) > 0) { - foreach($this->_bcc_array as $val) + foreach ($this->_bcc_array as $val) { if ($val != "") { @@ -1672,7 +1672,7 @@ class CI_Email { $errstr, $this->smtp_timeout); - if( ! is_resource($this->_smtp_connect)) + if ( ! is_resource($this->_smtp_connect)) { $this->_set_error_message('email_smtp_error', $errno." ".$errstr); return FALSE; diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c6d7c2976..adfd17db1 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -1040,7 +1040,7 @@ class CI_Form_validation { return $this->valid_email(trim($str)); } - foreach(explode(',', $str) as $email) + foreach (explode(',', $str) as $email) { if (trim($email) != '' && $this->valid_email(trim($email)) === FALSE) { diff --git a/system/libraries/Profiler.php b/system/libraries/Profiler.php index 6587eae0b..8a1f18ced 100644 --- a/system/libraries/Profiler.php +++ b/system/libraries/Profiler.php @@ -415,7 +415,7 @@ class CI_Profiler { $output .= "\n\n\n"; - foreach(array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) + foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header) { $val = (isset($_SERVER[$header])) ? $_SERVER[$header] : ''; $output .= "\n"; @@ -446,7 +446,7 @@ class CI_Profiler { $output .= "\n\n
".$header."  ".$val."
\n"; - foreach($this->CI->config->config as $config=>$val) + foreach ($this->CI->config->config as $config=>$val) { if (is_array($val)) { diff --git a/system/libraries/Security.php b/system/libraries/Security.php index ba64c7326..91896866f 100644 --- a/system/libraries/Security.php +++ b/system/libraries/Security.php @@ -373,7 +373,7 @@ class CI_Security { $str = preg_replace("#<(/*)(script|xss)(.*?)\>#si", '[removed]', $str); } } - while($original != $str); + while ($original != $str); unset($original); diff --git a/system/libraries/Sha1.php b/system/libraries/Sha1.php index ad747a001..05a42345a 100644 --- a/system/libraries/Sha1.php +++ b/system/libraries/Sha1.php @@ -88,7 +88,7 @@ class CI_SHA { $oldd = $d; $olde = $e; - for($j = 0; $j < 80; $j++) + for ($j = 0; $j < 80; $j++) { if ($j < 16) { diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 485541630..2a1a95b16 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -108,7 +108,7 @@ class CI_Table { } $new = array(); - while(count($array) > 0) + while (count($array) > 0) { $temp = array_splice($array, 0, $col_limit); @@ -280,7 +280,7 @@ class CI_Table { $out .= $this->template['heading_row_start']; $out .= $this->newline; - foreach($this->heading as $heading) + foreach ($this->heading as $heading) { $temp = $this->template['heading_cell_start']; @@ -310,7 +310,7 @@ class CI_Table { $out .= $this->newline; $i = 1; - foreach($this->rows as $row) + foreach ($this->rows as $row) { if ( ! is_array($row)) { @@ -323,7 +323,7 @@ class CI_Table { $out .= $this->template['row_'.$name.'start']; $out .= $this->newline; - foreach($row as $cell) + foreach ($row as $cell) { $temp = $this->template['cell_'.$name.'start']; diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index e29b35c7a..b0a767822 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -94,7 +94,7 @@ class CI_Trackback { { $$item = $this->convert_ascii($$item); } - elseif($item == 'blog_name') + elseif ($item == 'blog_name') { $$item = $this->convert_ascii($$item); } @@ -261,7 +261,7 @@ class CI_Trackback { // Was it successful? $this->response = ""; - while( ! feof($fp)) + while ( ! feof($fp)) { $this->response .= fgets($fp, 128); } diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 8f84ffd7e..c8c42d885 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -214,7 +214,7 @@ class CI_Upload { $this->file_name = $this->_prep_filename($this->_file_name_override); // If no extension was provided in the file_name config item, use the uploaded one - if(strpos($this->_file_name_override, '.') === FALSE) + if (strpos($this->_file_name_override, '.') === FALSE) { $this->file_name .= $this->file_ext; } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 0d5a261f9..a24bca9b6 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -207,7 +207,7 @@ class CI_Xmlrpc { $this->data = array(); - foreach($incoming as $key => $value) + foreach ($incoming as $key => $value) { $this->data[$key] = $this->values_parsing($value); } @@ -232,7 +232,7 @@ class CI_Xmlrpc { { if (is_array($value) && array_key_exists(0, $value)) { - if ( ! isset($value['1']) OR (! isset($this->xmlrpcTypes[$value['1']]))) + if ( ! isset($value['1']) OR ( ! isset($this->xmlrpcTypes[$value['1']]))) { if (is_array($value[0])) { @@ -243,7 +243,7 @@ class CI_Xmlrpc { $temp = new XML_RPC_Values($value['0'], 'string'); } } - elseif(is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) + elseif (is_array($value['0']) && ($value['1'] == 'struct' OR $value['1'] == 'array')) { while (list($k) = each($value['0'])) { @@ -281,7 +281,7 @@ class CI_Xmlrpc { $this->error = $this->result->errstr; return FALSE; } - elseif( ! is_object($this->result->val)) + elseif ( ! is_object($this->result->val)) { $this->error = $this->result->errstr; return FALSE; @@ -392,7 +392,7 @@ class XML_RPC_Client extends CI_Xmlrpc return $r; } - if(empty($msg->payload)) + if (empty($msg->payload)) { // $msg = XML_RPC_Messages $msg->createPayload(); @@ -553,11 +553,11 @@ class XML_RPC_Response { $kind = $xmlrpc_val->kindOf(); - if($kind == 'scalar') + if ($kind == 'scalar') { return $xmlrpc_val->scalarval(); } - elseif($kind == 'array') + elseif ($kind == 'array') { reset($xmlrpc_val->me); list($a,$b) = each($xmlrpc_val->me); @@ -565,18 +565,18 @@ class XML_RPC_Response $arr = array(); - for($i = 0; $i < $size; $i++) + for ($i = 0; $i < $size; $i++) { $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); } return $arr; } - elseif($kind == 'struct') + elseif ($kind == 'struct') { reset($xmlrpc_val->me['struct']); $arr = array(); - while(list($key,$value) = each($xmlrpc_val->me['struct'])) + while (list($key,$value) = each($xmlrpc_val->me['struct'])) { $arr[$key] = $this->xmlrpc_decoder($value); } @@ -595,10 +595,8 @@ class XML_RPC_Response $t = 0; if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) { - if ($utc == 1) - $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); - else - $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); + $fnc = ($utc == 1) ? 'gmmktime' : 'mktime'; + $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); } return $t; } @@ -628,7 +626,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->method_name = $method; if (is_array($pars) && count($pars) > 0) { - for($i=0; $iparams[] = $pars[$i]; @@ -646,7 +644,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->payload .= '' . $this->method_name . "\r\n"; $this->payload .= "\r\n"; - for($i=0; $iparams); $i++) + for ($i=0; $iparams); $i++) { // $p = XML_RPC_Values $p = $this->params[$i]; @@ -664,7 +662,7 @@ class XML_RPC_Message extends CI_Xmlrpc { $data = ''; - while($datum = fread($fp, 4096)) + while ($datum = fread($fp, 4096)) { $data .= $datum; } @@ -684,7 +682,7 @@ class XML_RPC_Message extends CI_Xmlrpc // Check for data //------------------------------------- - if($data == "") + if ($data == "") { error_log($this->xmlrpcstr['no_data']); $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); @@ -1108,7 +1106,7 @@ class XML_RPC_Message extends CI_Xmlrpc $this->xh[$the_parser]['lv'] = 2; // Found a value } - if( ! @isset($this->xh[$the_parser]['ac'])) + if ( ! @isset($this->xh[$the_parser]['ac'])) { $this->xh[$the_parser]['ac'] = ''; } @@ -1174,11 +1172,11 @@ class XML_RPC_Message extends CI_Xmlrpc { $kind = $param->kindOf(); - if($kind == 'scalar') + if ($kind == 'scalar') { return $param->scalarval(); } - elseif($kind == 'array') + elseif ($kind == 'array') { reset($param->me); list($a,$b) = each($param->me); @@ -1192,13 +1190,13 @@ class XML_RPC_Message extends CI_Xmlrpc return $arr; } - elseif($kind == 'struct') + elseif ($kind == 'struct') { reset($param->me['struct']); $arr = array(); - while(list($key,$value) = each($param->me['struct'])) + while (list($key,$value) = each($param->me['struct'])) { $arr[$key] = $this->decode_message($value); } @@ -1343,7 +1341,7 @@ class XML_RPC_Values extends CI_Xmlrpc // struct $rs .= "\n"; reset($val); - while(list($key2, $val2) = each($val)) + while (list($key2, $val2) = each($val)) { $rs .= "\n{$key2}\n"; $rs .= $this->serializeval($val2); diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php index 80633c708..666327d5c 100644 --- a/system/libraries/Zip.php +++ b/system/libraries/Zip.php @@ -289,7 +289,7 @@ class CI_Zip { while (FALSE !== ($file = readdir($fp))) { - if(substr($file, 0, 1) == '.') + if (substr($file, 0, 1) == '.') { continue; } -- cgit v1.2.3-24-g4f1b From c3a4a8d973b9c0a7cc935d150b8b1c6898037c45 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Mon, 14 Feb 2011 13:40:08 -0500 Subject: Whitespace cleanup in db classes --- system/database/DB.php | 2 +- system/database/DB_active_rec.php | 6 +++--- system/database/DB_driver.php | 12 ++++++------ system/database/DB_forge.php | 2 +- system/database/DB_result.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 4 ++-- system/database/drivers/mysql/mysql_driver.php | 10 +++++----- system/database/drivers/mysqli/mysqli_driver.php | 10 +++++----- system/database/drivers/oci8/oci8_driver.php | 6 +++--- system/database/drivers/odbc/odbc_driver.php | 4 ++-- system/database/drivers/postgre/postgre_driver.php | 4 ++-- system/database/drivers/sqlite/sqlite_driver.php | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) (limited to 'system') diff --git a/system/database/DB.php b/system/database/DB.php index 513e5aefd..93ee3922a 100644 --- a/system/database/DB.php +++ b/system/database/DB.php @@ -88,7 +88,7 @@ function &DB($params = '', $active_record_override = NULL) { parse_str($dns['query'], $extra); - foreach($extra as $key => $val) + foreach ($extra as $key => $val) { // booleans please if (strtoupper($val) == "TRUE") diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php index ce9d1c1af..06ec3cd95 100644 --- a/system/database/DB_active_rec.php +++ b/system/database/DB_active_rec.php @@ -1167,7 +1167,7 @@ class CI_DB_active_record extends CI_DB_driver { { $clean = array(); - foreach($row as $value) + foreach ($row as $value) { $clean[] = $this->escape($value); } @@ -1425,7 +1425,7 @@ class CI_DB_active_record extends CI_DB_driver { $index_set = FALSE; $clean = array(); - foreach($v as $k2 => $v2) + foreach ($v as $k2 => $v2) { if ($k2 == $index) { @@ -1569,7 +1569,7 @@ class CI_DB_active_record extends CI_DB_driver { } elseif (is_array($table)) { - foreach($table as $single_table) + foreach ($table as $single_table) { $this->delete($single_table, $where, $limit, FALSE); } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 2d8f592e3..e7a9de475 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -767,7 +767,7 @@ class CI_DB_driver { if ($query->num_rows() > 0) { - foreach($query->result_array() as $row) + foreach ($query->result_array() as $row) { if (isset($row['TABLE_NAME'])) { @@ -834,7 +834,7 @@ class CI_DB_driver { $query = $this->query($sql); $retval = array(); - foreach($query->result_array() as $row) + foreach ($query->result_array() as $row) { if (isset($row['COLUMN_NAME'])) { @@ -904,7 +904,7 @@ class CI_DB_driver { $fields = array(); $values = array(); - foreach($data as $key => $val) + foreach ($data as $key => $val) { $fields[] = $this->_escape_identifiers($key); $values[] = $this->escape($val); @@ -932,7 +932,7 @@ class CI_DB_driver { } $fields = array(); - foreach($data as $key => $val) + foreach ($data as $key => $val) { $fields[$this->_protect_identifiers($key)] = $this->escape($val); } @@ -1175,7 +1175,7 @@ class CI_DB_driver { $trace = debug_backtrace(); - foreach($trace as $call) + foreach ($trace as $call) { if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) { @@ -1248,7 +1248,7 @@ class CI_DB_driver { { $escaped_array = array(); - foreach($item as $k => $v) + foreach ($item as $k => $v) { $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v); } diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 27f2c372d..a71fca78f 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -99,7 +99,7 @@ class CI_DB_forge { { if (is_array($key)) { - foreach($key as $one) + foreach ($key as $one) { $this->add_key($one, $primary); } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index fb4268c21..76e1d6abb 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -78,7 +78,7 @@ class CI_DB_result { while ($row = $this->_fetch_object()) { $object = new $class_name(); - foreach($row as $key => $value) + foreach ($row as $key => $value) { $object->$key = $value; } diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 5a69132cd..5048c0b4a 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -253,7 +253,7 @@ class CI_DB_mssql_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -551,7 +551,7 @@ class CI_DB_mssql_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 72c834b8f..4ff9b0a11 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -286,7 +286,7 @@ class CI_DB_mysql_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -590,7 +590,7 @@ class CI_DB_mysql_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key . ' = ' . $val; } @@ -627,11 +627,11 @@ class CI_DB_mysql_driver extends CI_DB { $ids = array(); $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach($values as $key => $val) + foreach ($values as $key => $val) { $ids[] = $val[$index]; - foreach(array_keys($val) as $field) + foreach (array_keys($val) as $field) { if ($field != $index) { @@ -643,7 +643,7 @@ class CI_DB_mysql_driver extends CI_DB { $sql = "UPDATE ".$table." SET "; $cases = ''; - foreach($final as $k => $v) + foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; foreach ($v as $row) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 8942100d4..ccdabce1a 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -287,7 +287,7 @@ class CI_DB_mysqli_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -571,7 +571,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } @@ -607,11 +607,11 @@ class CI_DB_mysqli_driver extends CI_DB { $ids = array(); $where = ($where != '' AND count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach($values as $key => $val) + foreach ($values as $key => $val) { $ids[] = $val[$index]; - foreach(array_keys($val) as $field) + foreach (array_keys($val) as $field) { if ($field != $index) { @@ -623,7 +623,7 @@ class CI_DB_mysqli_driver extends CI_DB { $sql = "UPDATE ".$table." SET "; $cases = ''; - foreach($final as $k => $v) + foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; foreach ($v as $row) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 64f53cc3f..14df104ff 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -253,7 +253,7 @@ class CI_DB_oci8_driver extends CI_DB { $sql = "begin $package.$procedure("; $have_cursor = FALSE; - foreach($params as $param) + foreach ($params as $param) { $sql .= $param['name'] . ","; @@ -395,7 +395,7 @@ class CI_DB_oci8_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -655,7 +655,7 @@ class CI_DB_oci8_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index c8e03c356..81e0d7cf2 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -264,7 +264,7 @@ class CI_DB_odbc_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -523,7 +523,7 @@ class CI_DB_odbc_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 81ca6e051..47ff36246 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -283,7 +283,7 @@ class CI_DB_postgre_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -568,7 +568,7 @@ class CI_DB_postgre_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 5bfc1f558..eb4e585b3 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -280,7 +280,7 @@ class CI_DB_sqlite_driver extends CI_DB { { if (is_array($str)) { - foreach($str as $key => $val) + foreach ($str as $key => $val) { $str[$key] = $this->escape_str($val, $like); } @@ -537,7 +537,7 @@ class CI_DB_sqlite_driver extends CI_DB { */ function _update($table, $values, $where, $orderby = array(), $limit = FALSE) { - foreach($values as $key => $val) + foreach ($values as $key => $val) { $valstr[] = $key." = ".$val; } -- cgit v1.2.3-24-g4f1b From f46d9d6abdc6ae71a3307cf76f7064d0aa18eb65 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Mon, 14 Feb 2011 21:53:48 +0000 Subject: Removed Migration code for now, will come back later. --- system/libraries/Migration.php | 336 ----------------------------------------- 1 file changed, 336 deletions(-) delete mode 100644 system/libraries/Migration.php (limited to 'system') diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php deleted file mode 100644 index 73c55c346..000000000 --- a/system/libraries/Migration.php +++ /dev/null @@ -1,336 +0,0 @@ - $val) - { - $this->{'_' . $key} = $val; - } - - log_message('debug', 'Migrations class initialized'); - - // Are they trying to use migrations while it is disabled? - if ($this->_migration_enabled !== TRUE) - { - show_error('Migrations has been loaded but is disabled or set up incorrectly.'); - } - - // If not set, set it - $this->_migration_path == '' OR $this->_migration_path = APPPATH . 'migrations/'; - - // Add trailing slash if not set - $this->_migration_path = rtrim($this->_migration_path, '/').'/'; - - // They'll probably be using dbforge - $this->load->dbforge(); - - // If the migrations table is missing, make it - if ( ! $this->db->table_exists('migrations')) - { - $this->dbforge->add_field(array( - 'version' => array('type' => 'INT', 'constraint' => 3), - )); - - $this->dbforge->create_table('migrations', TRUE); - - $this->db->insert('migrations', array('version' => 0)); - } - } - - // -------------------------------------------------------------------- - - /** - * Migrate to a schema version - * - * Calls each migration step required to get to the schema version of - * choice - * - * @access public - * @param $version integer Target schema version - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded - */ - function version($target_version) - { - $start = $current_version = $this->_get_version(); - $stop = $target_version; - - if ($target_version > $current_version) - { - // Moving Up - ++$start; - ++$stop; - $step = 1; - } - - else - { - // Moving Down - $step = -1; - } - - $method = $step === 1 ? 'up' : 'down'; - $migrations = array(); - - // We now prepare to actually DO the migrations - // But first let's make sure that everything is the way it should be - for ($i = $start; $i != $stop; $i += $step) - { - $f = glob(sprintf($this->_migration_path . '%03d_*.php', $i)); - - // Only one migration per step is permitted - if (count($f) > 1) - { - $this->error = sprintf($this->lang->line('multiple_migration_version'), $i); - return FALSE; - } - - // Migration step not found - if (count($f) == 0) - { - // If trying to migrate up to a version greater than the last - // existing one, migrate to the last one. - if ($step == 1) - { - break; - } - - // If trying to migrate down but we're missing a step, - // something must definitely be wrong. - $this->error = sprintf($this->lang->line('migration_not_found'), $i); - return FALSE; - } - - $file = basename($f[0]); - $name = basename($f[0], '.php'); - - // Filename validations - if (preg_match('/^\d{3}_(\w+)$/', $name, $match)) - { - $match[1] = strtolower($match[1]); - - // Cannot repeat a migration at different steps - if (in_array($match[1], $migrations)) - { - $this->error = sprintf($this->lang->line('multiple_migrations_name'), $match[1]); - return FALSE; - } - - include $f[0]; - $class = 'Migration_' . ucfirst($match[1]); - - if ( ! class_exists($class)) - { - $this->error = sprintf($this->lang->line('migration_class_doesnt_exist'), $class); - return FALSE; - } - - if ( ! is_callable(array($class, 'up')) || ! is_callable(array($class, 'down'))) - { - $this->error = sprintf($this->lang->line('wrong_migration_interface'), $class); - return FALSE; - } - - $migrations[] = $match[1]; - } - else - { - $this->error = sprintf($this->lang->line('invalid_migration_filename'), $file); - return FALSE; - } - } - - $this->log('Current schema version: ' . $current_version); - - $version = $i + ($step == 1 ? -1 : 0); - - // If there is nothing to do so quit - if ($migrations === array()) - { - return TRUE; - } - - $this->log('Moving ' . $method . ' to version ' . $version); - - // Loop through the migrations - foreach ($migrations AS $migration) - { - // Run the migration class - $class = 'Migration_' . ucfirst(strtolower($migration)); - call_user_func(array(new $class, $method)); - - $current_version += $step; - $this->_update_version($current_version); - } - - $this->log('All done. Schema is at version '.$current_version); - - return $current_version; - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the latest migration - * - * @access public - * @return mixed true if already latest, false if failed, int if upgraded - */ - public function latest() - { - if ( ! $migrations = $this->find_migrations()) - { - throw new Exception('no_migrations_found'); - return false; - } - - $last_migration = basename(end($migrations)); - - // Calculate the last migration step from existing migration - // filenames and procceed to the standard version migration - $last_version = intval(substr($last_migration, 0, 3)); - return $this->version($last_version); - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the migration version set in config - * - * @access public - * @return mixed true if already current, false if failed, int if upgraded - */ - public function current() - { - $version = $this->_migration_version; - return $this->version($version); - } - - // -------------------------------------------------------------------- - - /** - * Set's the schema to the latest migration - * - * @access public - * @return mixed true if already latest, false if failed, int if upgraded - */ - - protected static function find_migrations() - { - // Load all *_*.php files in the migrations path - $files = glob($this->_migration_path . '*_*.php'); - $file_count = count($files); - - for ($i = 0; $i < $file_count; $i++) - { - // Mark wrongly formatted files as false for later filtering - $name = basename($files[$i], '.php'); - if ( ! preg_match('/^\d{3}_(\w+)$/', $name)) - { - $files[$i] = FALSE; - } - } - - sort($files); - - return $files; - } - - // -------------------------------------------------------------------- - - /** - * Retrieves current schema version - * - * @access private - * @return integer Current Schema version - */ - private function _get_version() - { - $row = $this->db->get('migrations')->row(); - return $row ? $row->version : 0; - } - - // -------------------------------------------------------------------- - - /** - * Stores the current schema version - * - * @access private - * @param $migrations integer Schema version reached - * @return void Outputs a report of the migration - */ - private function _update_version($migrations) - { - return $this->db->update('migrations', array( - 'version' => $migrations - )); - } - - // -------------------------------------------------------------------- - - /** - * Stores the current schema version - * - * @access private - * @param $migrations integer Schema version reached - * @return void Outputs a report of the migration - */ - private function log($text) - { - echo $text.'
'; - } - - // -------------------------------------------------------------------- - - /** - * Enable the use of CI super-global - * - * @access public - * @param $var - * @return mixed - */ - public function __get($var) - { - return get_instance()->$var; - } -} \ No newline at end of file -- cgit v1.2.3-24-g4f1b