Beispiel #1
0
 /**
  * 
  */
 public static function serviceRoute()
 {
     global $goLoader;
     Debug::debug($_SERVER['argv']);
     if (isset($_SERVER['argv']) && is_array($_SERVER['argv'])) {
         $lsModule = '';
         $lsController = '';
         $lsAction = '';
         $laParams = array();
         foreach ($_SERVER['argv'] as $lsArg) {
             $laArg = explode("=", $lsArg);
             switch ($laArg[0]) {
                 case '--module':
                 case '--m':
                 case '-m':
                     $lsModule = $laArg[1];
                     break;
                 case '--controller':
                 case '--c':
                 case '-c':
                     $lsController = $laArg[1];
                     break;
                 case '--action':
                 case '--a':
                 case '-a':
                     $lsAction = $laArg[1];
                     break;
                 default:
                     if (isset($laArg[1])) {
                         $laParams['ARG'][$laArg[0]] = $laArg[1];
                     }
                     break;
             }
         }
         if (empty($lsModule)) {
             $lsModule = $lsAction;
         }
         if (empty($lsController)) {
             $lsController = $lsModule;
         }
         if (empty($lsAction)) {
             $lsAction = $lsController;
         }
         if (empty($lsModule) && empty($lsController) && empty($lsAction)) {
             $lsModule = $lsController = $lsAction = 'index';
         }
         $lsPath = Autoload::getNamespace(ucfirst($lsModule), $goLoader);
         $lsService = $lsPath . DS . ucfirst($lsModule) . DS . 'Controller' . DS . ucfirst($lsController) . "Controller.php";
         $lsClass = '\\' . ucfirst($lsModule) . '\\' . 'Controller' . '\\' . ucfirst($lsController) . "Controller";
         if (TESTMOD) {
             $lsMethod = $lsAction . 'Test';
         } else {
             $lsMethod = $lsAction . 'Action';
         }
         $laService['service'] = $lsService;
         $laService['class'] = $lsClass;
         $laService['method'] = $lsMethod;
         $laService['module'] = ucfirst($lsModule);
         $laService['controller'] = ucfirst($lsController);
         $laService['action'] = $lsAction;
         Debug::debug($laService);
         Debug::debug($laParams);
         self::run($laService, $laParams);
     } else {
         //Se o service não foi encontrado
         System::exitError("Params not found!");
     }
 }
Beispiel #2
0
 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);
     }
 }