diff options
-rw-r--r-- | kohana/config/inflector.php | 1 | ||||
-rw-r--r-- | kohana/core/Kohana.php | 30 | ||||
-rw-r--r-- | kohana/helpers/html.php | 2 | ||||
-rw-r--r-- | kohana/libraries/Input.php | 15 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 49 | ||||
-rw-r--r-- | kohana/libraries/View.php | 2 |
6 files changed, 54 insertions, 45 deletions
diff --git a/kohana/config/inflector.php b/kohana/config/inflector.php index 4fe73f76..64c0853c 100644 --- a/kohana/config/inflector.php +++ b/kohana/config/inflector.php @@ -53,4 +53,5 @@ $config['irregular'] = array 'goose' => 'geese', 'ox' => 'oxen', 'leaf' => 'leaves', + 'course' => 'courses', ); diff --git a/kohana/core/Kohana.php b/kohana/core/Kohana.php index c4812e63..76964fbd 100644 --- a/kohana/core/Kohana.php +++ b/kohana/core/Kohana.php @@ -109,7 +109,7 @@ final class Kohana { if (function_exists('date_default_timezone_set')) { - $timezone = Kohana::config('locale.timezone'); + $timezone = self::config('locale.timezone'); // Set default timezone, due to increased validation of date settings // which cause massive amounts of E_NOTICEs to be generated in PHP 5.2+ @@ -168,10 +168,10 @@ final class Kohana { // Enable Kohana output handling Event::add('system.shutdown', array('Kohana', 'shutdown')); - if (Kohana::config('core.enable_hooks') === TRUE) + if (self::config('core.enable_hooks') === TRUE) { // Find all the hook files - $hooks = Kohana::list_files('hooks', TRUE); + $hooks = self::list_files('hooks', TRUE); foreach ($hooks as $file) { @@ -700,7 +700,7 @@ final class Kohana { // Fetch benchmark for page execution time $benchmark = Benchmark::get(SYSTEM_BENCHMARK.'_total_execution'); - if (Kohana::config('core.render_stats') === TRUE) + if (self::config('core.render_stats') === TRUE) { // Replace the global template variables $output = str_replace( @@ -724,7 +724,7 @@ final class Kohana { ); } - if ($level = Kohana::config('core.output_compression') AND ini_get('output_handler') !== 'ob_gzhandler' AND (int) ini_get('zlib.output_compression') === 0) + if ($level = self::config('core.output_compression') AND ini_get('output_handler') !== 'ob_gzhandler' AND (int) ini_get('zlib.output_compression') === 0) { if ($level < 1 OR $level > 9) { @@ -1123,7 +1123,7 @@ final class Kohana { if ($path === FALSE) { - $paths = array_reverse(Kohana::include_paths()); + $paths = array_reverse(self::include_paths()); foreach ($paths as $path) { @@ -1173,7 +1173,7 @@ final class Kohana { $group = $group[0]; // Get locale name - $locale = Kohana::config('locale.language.0'); + $locale = self::config('locale.language.0'); if ( ! isset(self::$internal_cache['language'][$locale][$group])) { @@ -1211,7 +1211,7 @@ final class Kohana { if ($line === NULL) { - Kohana::log('error', 'Missing i18n entry '.$key.' for language '.$locale); + self::log('error', 'Missing i18n entry '.$key.' for language '.$locale); // Return the key string as fallback return $key; @@ -1364,20 +1364,20 @@ final class Kohana { // Return the raw string if ($key === 'agent') - return Kohana::$user_agent; + return self::$user_agent; if ($info === NULL) { // Parse the user agent and extract basic information - $agents = Kohana::config('user_agents'); + $agents = self::config('user_agents'); foreach ($agents as $type => $data) { foreach ($data as $agent => $name) { - if (stripos(Kohana::$user_agent, $agent) !== FALSE) + if (stripos(self::$user_agent, $agent) !== FALSE) { - if ($type === 'browser' AND preg_match('|'.preg_quote($agent).'[^0-9.]*+([0-9.][0-9.a-z]*)|i', Kohana::$user_agent, $match)) + if ($type === 'browser' AND preg_match('|'.preg_quote($agent).'[^0-9.]*+([0-9.][0-9.a-z]*)|i', self::$user_agent, $match)) { // Set the browser version $info['version'] = $match[1]; @@ -1445,11 +1445,11 @@ final class Kohana { { case 'accept_lang': // Check if the lange is accepted - return in_array($compare, Kohana::user_agent('languages')); + return in_array($compare, self::user_agent('languages')); break; case 'accept_charset': // Check if the charset is accepted - return in_array($compare, Kohana::user_agent('charsets')); + return in_array($compare, self::user_agent('charsets')); break; default: // Invalid comparison @@ -1505,7 +1505,7 @@ final class Kohana { if (isset($entry['file'])) { - $temp .= Kohana::lang('core.error_file_line', preg_replace('!^'.preg_quote(DOCROOT).'!', '', $entry['file']), $entry['line']); + $temp .= self::lang('core.error_file_line', preg_replace('!^'.preg_quote(DOCROOT).'!', '', $entry['file']), $entry['line']); } $temp .= '<pre>'; diff --git a/kohana/helpers/html.php b/kohana/helpers/html.php index d1f09612..37f80ae3 100644 --- a/kohana/helpers/html.php +++ b/kohana/helpers/html.php @@ -419,7 +419,7 @@ class html_Core { $compiled = ''; foreach ($attrs as $key => $val) { - $compiled .= ' '.$key.'="'.$val.'"'; + $compiled .= ' '.$key.'="'.html::specialchars($val).'"'; } return $compiled; diff --git a/kohana/libraries/Input.php b/kohana/libraries/Input.php index a0004621..3cdef0b8 100644 --- a/kohana/libraries/Input.php +++ b/kohana/libraries/Input.php @@ -83,16 +83,13 @@ class Input_Core { $preserve = array('GLOBALS', '_REQUEST', '_GET', '_POST', '_FILES', '_COOKIE', '_SERVER', '_ENV', '_SESSION'); // This loop has the same effect as disabling register_globals - foreach ($GLOBALS as $key => $val) + foreach (array_diff(array_keys($GLOBALS), $preserve) as $key) { - if ( ! in_array($key, $preserve)) - { - global $$key; - $$key = NULL; - - // Unset the global variable - unset($GLOBALS[$key], $$key); - } + global $$key; + $$key = NULL; + + // Unset the global variable + unset($GLOBALS[$key], $$key); } // Warn the developer about register globals diff --git a/kohana/libraries/ORM.php b/kohana/libraries/ORM.php index 51b6069c..6ee4c28f 100644 --- a/kohana/libraries/ORM.php +++ b/kohana/libraries/ORM.php @@ -59,10 +59,13 @@ class ORM_Core { // Database configuration protected $db = 'default'; protected $db_applied = array(); - + // With calls already applied protected $with_applied = array(); + // Stores column information for ORM models + protected static $column_cache = array(); + /** * Creates and returns a new model. * @@ -109,7 +112,7 @@ class ORM_Core { $this->load_values((array) $id); } elseif (!empty($id)) - { + { // Find an object $this->find($id); } @@ -324,14 +327,14 @@ class ORM_Core { { // many<>many relationship return $this->related[$column] = $model - ->in($model->primary_key, $this->changed_relations[$column]) + ->in($model->table_name.'.'.$model->primary_key, $this->changed_relations[$column]) ->find_all(); } else { // empty many<>many relationship return $this->related[$column] = $model - ->where($model->primary_key, NULL) + ->where($model->table_name.'.'.$model->primary_key, NULL) ->find_all(); } } @@ -453,12 +456,12 @@ class ORM_Core { return $object; } - + /** * Binds another one-to-one object to this model. One-to-one objects * can be nested using 'object1:object2' syntax * - * @param string $object + * @param string $object * @return void */ public function with($object) @@ -471,7 +474,7 @@ class ORM_Core { $prefix = $table = $object; - // Split object parts + // Split object parts $objects = explode(':', $object); $object = $this; foreach ($objects as $object_part) @@ -479,21 +482,21 @@ class ORM_Core { // Go down the line of objects to find the given target $parent = $object; $object = $parent->related_object($object_part); - + if ( ! $object) { // Can't find related object return $this; } } - + $table = $object_part; - + if ($this->table_names_plural) { $table = inflector::plural($table); } - + // Pop-off top object to get the parent object (user:photo:tag's parent is user:photo) array_pop($objects); $parent_prefix = implode(':', $objects); @@ -511,10 +514,10 @@ class ORM_Core { $this->with($parent_prefix); } } - + // Add to with_applied to prevent duplicate joins $this->with_applied[$prefix] = TRUE; - + // Use the keys of the empty object to determine the columns $select = array_keys($object->as_array()); foreach ($select as $i => $column) @@ -530,7 +533,7 @@ class ORM_Core { $foreign_key = $object_part.'_'.$object->primary_key; if (array_key_exists($foreign_key, $parent->object)) - { + { // Foreign key exists in the joined object's parent $join_col1 = $object->foreign_key(TRUE, $prefix); $join_col2 = $parent_prefix.'.'.$foreign_key; @@ -542,7 +545,7 @@ class ORM_Core { } // Join the related object into the result - $this->db->join($object->table_name.' AS '.$prefix, $join_col1, $join_col2, 'LEFT'); + $this->db->join($object->table_name.' AS '.$this->db->table_prefix().$prefix, $join_col1, $join_col2, 'LEFT'); return $this; } @@ -887,8 +890,16 @@ class ORM_Core { { if ($force === TRUE OR empty($this->table_columns)) { - // Load table columns - $this->table_columns = $this->db->list_fields($this->table_name, TRUE); + if (isset(self::$column_cache[$this->object_name])) + { + // Use cached column information + $this->table_columns = self::$column_cache[$this->object_name]; + } + else + { + // Load table columns + self::$column_cache[$this->object_name] = $this->table_columns = $this->db->list_fields($this->table_name, TRUE); + } } return $this; @@ -901,10 +912,10 @@ class ORM_Core { * @return boolean */ public function has(ORM $model) - { + { if ($model->table_names_plural) { - // Get the plural object name as the related name + // Get the plural object name as the related name $related = $model->object_plural; } else diff --git a/kohana/libraries/View.php b/kohana/libraries/View.php index 7a49fd84..c440be10 100644 --- a/kohana/libraries/View.php +++ b/kohana/libraries/View.php @@ -222,7 +222,7 @@ class View_Core { * @return mixed variable value if the key is found * @return void if the key is not found */ - public function __get($key) + public function &__get($key) { if (isset($this->kohana_local_data[$key])) return $this->kohana_local_data[$key]; |