view = $view = $this->createComponentView ($name); $data = array (); if (count ($args)) { $data = current ($args); if (is_array ($data)) { foreach ($data as $key=>$value) { $view->$key = $value; } } else { throw new Exception ("Invalid component call. Use an array in order to pass arguments to a component."); } } $this->runThemeModel ($name, $view, $data); $params = array ( 'name' => $name, 'view' => $view, ); Event::run ('componentcontroller.model.after', $params); echo $view->render (); } catch (Kohana_Database_Exception $e) { throw $e; } catch (Exception $e) { echo $e->getMessage (); } } function runThemeModel ($name, $view, $args) { $class_name = 'Theme_Model_' . $name; if (! class_exists ($class_name) && Kohana::config ('core.modules')) { $module_filename = Kohana::find_file ('libraries', 'Theme/Model/'.$name); if ($module_filename) { require_once $module_filename; } } if (class_exists ($class_name)) { $model = new $class_name; if (! $model instanceof Theme_Model) { throw new Exception ('Invalid type. Theme_Model is expected.'); } $model->setView ($view); $model->setParams ($args); $model->render (); } } function createComponentView ($name) { $path = $this->getComponentDir () . join (DIRECTORY_SEPARATOR, $this->getPath ($name)); $view = new View_Frontend ($path); $this->getParentView ()->exportGlobalVars ($view); return $view; } function getComponentDir () { return 'components/'; } function __get ($name) { $result = new self (); $result->setParentView ($this->getParentView ()); $result->setName ($name); $result->setParent ($this); return $result; } function setParent ($parent) { $this->parent = $parent; } function getParent () { return $this->parent; } function hasParent () { return isset ($this->parent); } function setName ($name) { $this->name = $name; } function getName () { return $this->name; } function hasName () { return isset ($this->name); } function getPath ($additional = array ()) { if (!is_array ($additional)) { $additional = array ($additional); } $result = $additional; $object = $this; do { array_unshift ($result, $object->getName ()); } while ($object->hasParent () and $object = $object->getParent () and $object->hasName ()); return $result; } function setParentView ($parent_view) { $this->parent_view = $parent_view; } function getParentView () { return $this->parent_view; } }