/** * Render the current view. * * @return void **/ public function render() { $registry = Components\Registry::instance(); $plugins = $registry->plugins; $vars = $registry->get_view_vars(); $vars['current_controller'] = $registry->controller; $vars['current_action'] = $registry->action; include_once 'application_helper.php'; $helper_classes = array(); $helper_names = array(); foreach (glob(VALET_ROOT . "/core/libs/helpers/*.php") as $file) { $class = str_replace(".php", "", basename($file)); $class = \Inflector::camelize($class); include_once $file; $helper_names[] = $class; } $helper_names[] = "ApplicationHelper"; $controller_helper = $registry->helper(); if (@(include_once \Inflector::underscore($controller_helper))) { $helper_names[] = $controller_helper; } foreach ($helper_names as $class) { $helper = new $class(); foreach (get_class_methods($helper) as $method) { if (substr($method, 0, 1) != '_') { $helper_classes[$method] = $helper; } } } if (!$this->_find_view($registry->view)) { throw new \Error("The view '" . $registry->view . "' could not be found."); } $file = new File($registry->view . ".phtml", $vars, $helper_classes); print $file; }
/** * Construct our page. * * @return void **/ public function __construct($file, &$vars, &$helpers = array()) { $this->_vars = $vars; $this->_helpers = $helpers; extract($this->_vars, EXTR_SKIP); ob_start(); include $file; $this->_page_content = ob_get_clean(); ob_start(); include "layouts/" . Components\Registry::instance()->layout . ".phtml"; $result = ob_get_clean(); $this->_template_content = $result; }
/** * Find the default route. * * @return void **/ private function _default($route) { if (empty($route) || $route == "/") { $this->_connect("index", "index", array()); return; } $parts = explode("/", $route); $paths = array(VALET_ROOT . "/app/controllers/"); $found = false; $plugins = Components\Registry::instance()->plugins; if (isset($plugins) && is_array($plugins)) { foreach ($plugins as $plugin) { $plugin_path = VALET_ROOT . "/vendor/plugins/" . $plugin . "/app/controllers"; if (is_dir($plugin_path)) { array_push($paths, $plugin_path . "/"); } else { throw new \Error("The plugin '{$plugin}' was not found."); } } } $class_path = array(); foreach ($paths as $path) { $namespaced = false; foreach ($parts as $part) { if (is_dir($path . $part)) { $path = $path . $part . "/"; $class_path[] = $part; $namespaced = true; continue; } if (is_file($path . $part . "_controller.php")) { $path = $path . $part; $class_path[] = $part; $found = true; break; } break; } if ($found == true) { break; } else { if ($namespaced == true && $this->_find_controller(implode("/", $class_path) . "/index_controller.php")) { $found = true; $class_path[] = "index"; } else { continue; } } } if ($found == false) { $this->_connect('index', array_shift($parts), $parts); } else { array_shift($parts); $this->_connect(implode("/", $class_path), array_shift($parts), $parts); } }