public static function add($path, $controller, $method) { if (isset(self::$controller)) return true; // Get URL Variables preg_match_all('/\(\:(.+?)\)/', $path, $matches); $URLVars = $matches[1]; // Generate URL Parser - '/^\/example\/([^\/]+?)\/$/i' $path = preg_replace(self::$search, self::$replace, $path); if (preg_match($path, self::$url, $values)) { // Path Found Set Vars and Route array_shift($values); self::$controller = $controller; self::$method = $method; // Add Params to Method Call if (!empty($values)) foreach(array_combine($URLVars, $values) as $key => $value) self::$params[] = $value; } }
/** * Build Rewrite * * Construye la estructura de ejecución de la APP desde la URL. * * @author Adrián Méndez <*****@*****.**> */ public static function build_rewrite($request) { $aGet = explode('/', $request); foreach ($aGet as $k => $v) { switch ($k) { case 0: $v = preg_replace('/^(\\_|[ ])+/', NULL, $v); strtolower($v); if (!is_null($v)) { self::$controller = ucfirst($v); } break; case 1: $v = preg_replace('/^(\\_|[ ])+/', NULL, $v); strtolower($v); if (!is_null($v)) { self::$action = $v; } break; default: if (!is_null($v)) { self::$getAttrs[] = $v; } break; } } return true; }