public static function app_from_uri($uri) { $uri = moojon_uri::clean_uri($uri); $route_match = moojon_routes::map($uri); $data = $route_match->get_params(); foreach ($data as $key => $value) { moojon_request::set($key, $value); } $app = $data['app']; self::require_view_functions(); require_once moojon_paths::get_app_path($app); $app_class = self::get_app_class($app); return new $app_class($uri); }
public static function render() { if (ENVIRONMENT != 'production') { $div = new moojon_div_tag(null, array('id' => 'debug')); $div->add_child(new moojon_h2_tag('Session')); $ul = new moojon_ul_tag(); foreach ($_SESSION as $key => $value) { if (is_array($value)) { $value = 'array(' . implode(', ', $value) . ')'; } $ul->add_child(new moojon_li_tag("{$key}: {$value}")); } $div->add_child($ul); $div->add_child(new moojon_h2_tag('Cookie')); $ul = new moojon_ul_tag(); foreach ($_COOKIE as $key => $value) { if (is_array($value)) { $value = 'array(' . implode(', ', $value) . ')'; } $ul->add_child(new moojon_li_tag("{$key}: {$value}")); } $div->add_child($ul); $div->add_child(new moojon_h2_tag('URL')); $ul = new moojon_ul_tag(); $app = APP; $controller = CONTROLLER; $action = ACTION; $ul->add_child(new moojon_li_tag("App: {$app}")); $ul->add_child(new moojon_li_tag("Controller: {$controller}")); $ul->add_child(new moojon_li_tag("Action: {$action}")); $div->add_child($ul); $div->add_child(new moojon_h2_tag('Paths')); $ul = new moojon_ul_tag(); $app_path = moojon_paths::get_app_path($app); $controller_path = moojon_paths::get_controller_path($app, $controller); $view_path = moojon_paths::get_view_path($app, $controller, $action); $ul->add_child(new moojon_li_tag("app_path: {$app_path}")); $ul->add_child(new moojon_li_tag("controller_path: {$controller_path}")); $ul->add_child(new moojon_li_tag("view_path: {$view_path}")); $div->add_child($ul); echo $div->render(); } }
protected static final function validate_matches($matches, $validate = true) { if ($validate) { if (!array_key_exists('app', $matches) || !array_key_exists('controller', $matches) || !array_key_exists('action', $matches)) { return false; } if ($path = moojon_paths::get_app_path($matches['app'])) { require_once $path; } else { return false; } if ($path = moojon_paths::get_controller_path($matches['app'], $matches['controller'])) { require_once $path; } else { return false; } if (!method_exists(self::get_controller_class($matches['controller']), $matches['action']) && !moojon_paths::get_view_path($matches['app'], $matches['controller'], $matches['action'])) { return false; } } return true; }