diff options
Diffstat (limited to 'kohana/libraries')
-rw-r--r-- | kohana/libraries/Input.php | 15 | ||||
-rw-r--r-- | kohana/libraries/ORM.php | 49 | ||||
-rw-r--r-- | kohana/libraries/View.php | 2 |
3 files changed, 37 insertions, 29 deletions
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]; |