public static function serviceRoute() { global $goLoader; Debug::debug($_SERVER['REQUEST_URI']); if (isset($_SERVER['REQUEST_URI'])) { $laParams = null; if (isset($_GET)) { $laParams['GET'] = $_GET; } if (isset($_POST)) { $laParams['POST'] = $_POST; } if (isset($_SERVER['Data-type']) && $_SERVER['Data-type'] == 'json' && isset($_SERVER['data'])) { $laParams['JSON'] = $_SERVER['data']; } if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'PUT') { $laParams['PUT'] = System::getPutData(); } if (isset($_FILES)) { $laParams['FILES'] = $_FILES; } //Separando o caminho e verificando quantos elementos tem $laRequestUri = explode("/", $_SERVER['REQUEST_URI']); $lnCount = 0; $lsQueryString = "?" . $_SERVER['QUERY_STRING']; //Removendo elementos vazios foreach ($laRequestUri as $lsPathUrl) { if (!empty($lsPathUrl) && $lsPathUrl != $lsQueryString) { $laPathUrl = explode('-', $lsPathUrl); $lsValueName = $laPathUrl[0]; unset($laPathUrl[0]); if (count($laPathUrl) > 0) { foreach ($laPathUrl as $lsValue) { $lsValueName .= ucfirst($lsValue); } } $laPath[] = $lsValueName; $lnCount++; } } if ($lnCount == 0) { $laPath[0] = 'index'; $lnCount = 1; } $laService['module'] = ucfirst($laPath[0]); $lsPath = Autoload::getNamespace($laService['module'], $goLoader); switch ($lnCount) { case 1: $lsService = $lsPath . DS . $laService['module'] . DS . 'Controller' . DS . $laService['module'] . "Controller.php"; $lsClass = '\\' . $laService['module'] . '\\Controller\\' . $laService['module'] . 'Controller'; $laService['controller'] = $laService['module']; $laService['action'] = $laPath[0]; break; case 2: $lsService = $lsPath . DS . $laService['module'] . DS . 'Controller' . DS . $laService['module'] . "Controller.php"; $lsClass = '\\' . $laService['module'] . '\\Controller\\' . $laService['module'] . 'Controller'; $laService['controller'] = $laService['module']; $laService['action'] = $laPath[1]; break; default: $lsService = $lsPath . DS . $laService['module'] . DS . 'Controller' . DS . ucfirst($laPath[1]) . "Controller.php"; $lsClass = '\\' . $laService['module'] . '\\' . 'Controller' . '\\' . ucfirst($laPath[1]) . "Controller"; $laService['controller'] = ucfirst($laPath[1]); $laService['action'] = $laPath[2]; } if (TESTMOD) { $lsMethod = $laService['action'] . 'Test'; } else { $lsMethod = $laService['action'] . 'Action'; } $laService['service'] = $lsService; $laService['class'] = $lsClass; $laService['method'] = $lsMethod; Debug::debug($laService); Debug::debug($laParams); self::run($laService, $laParams); } else { //Se o service não foi encontrado, retornar 404 not found para o client if (DEBUG) { Debug::debug("Service Not Found"); } else { header("HTTP/1.1 404 Service Not Found"); } exit(404); } }