set_filename($name, $type); } if (is_array($data) AND ! empty($data)) { $this->kohana_local_data = array_merge($this->kohana_local_data, $data); } } public function __isset($key = NULL) { return $this->is_set($key); } public function set_filename($name, $type = NULL) { if ($type == NULL) { $this->kohana_filename = Kohana::find_file('views', $name, TRUE); $this->kohana_filetype = EXT; } else { if ( ! in_array($type, Kohana::config('view.allowed_filetypes'))) throw new Kohana_Exception('core.invalid_filetype', $type); $this->kohana_filename = Kohana::find_file('views', $name, TRUE, $type); $this->kohana_filetype = Kohana::config('mimes.'.$type); if ($this->kohana_filetype == NULL) { $this->kohana_filetype = $type; } } return $this; } public function set($name, $value = NULL) { if (is_array($name)) { foreach ($name as $key => $value) { $this->__set($key, $value); } } else { $this->__set($name, $value); } return $this; } public function is_set( $key = FALSE ) { $result = FALSE; if (is_array($key)) { $result = array(); foreach ($key as $property) { $result[$property] = (array_key_exists($property, $this->kohana_local_data) OR array_key_exists($property, View::$kohana_global_data)) ? TRUE : FALSE; } } else { $result = (array_key_exists($key, $this->kohana_local_data) OR array_key_exists($key, View::$kohana_global_data)) ? TRUE : FALSE; } return $result; } public function bind($name, & $var) { $this->kohana_local_data[$name] =& $var; return $this; } public static function set_global($name, $value = NULL) { if (is_array($name)) { foreach ($name as $key => $value) { View::$kohana_global_data[$key] = $value; } } else { View::$kohana_global_data[$name] = $value; } } public function __set($key, $value) { $this->kohana_local_data[$key] = $value; } public function &__get($key) { if (isset($this->kohana_local_data[$key])) return $this->kohana_local_data[$key]; if (isset(View::$kohana_global_data[$key])) return View::$kohana_global_data[$key]; if (isset($this->$key)) return $this->$key; } public function __toString() { try { return $this->render(); } catch (Exception $e) { return (string) $e; } } public function render($print = FALSE, $renderer = FALSE) { if (empty($this->kohana_filename)) throw new Kohana_Exception('core.view_set_filename'); if (is_string($this->kohana_filetype)) { $data = array_merge(View::$kohana_global_data, $this->kohana_local_data); $output = Kohana::$instance->_kohana_load_view($this->kohana_filename, $data); if ($renderer !== FALSE AND is_callable($renderer, TRUE)) { $output = call_user_func($renderer, $output); } if ($print === TRUE) { echo $output; return; } } else { header('Content-Type: '.$this->kohana_filetype[0]); if ($print === TRUE) { if ($file = fopen($this->kohana_filename, 'rb')) { fpassthru($file); fclose($file); } return; } $output = file_get_contents($this->kohana_filename); } return $output; } }