/** * @var $command array */ private function dispatchCommand() { Safan::handler()->getObjectManager()->get('router')->checkCliCommand($this->command); if (Get::exists('module')) { $module = Get::str('module'); } else { return $this->getErrorMessage('Module Global Variable is not exists'); } if (Get::exists('controller')) { $controller = Get::str('controller'); } else { return $this->getErrorMessage('Controller Global Variable is not exists'); } if (Get::exists('action')) { $action = Get::str('action'); } else { return $this->getErrorMessage('Action Global Variable is not exists'); } // get all modules $modules = Safan::handler()->getModules(); if (isset($modules[$module]) && is_dir(APP_BASE_PATH . DS . $modules[$module])) { $nameSpace = '\\' . $module; $this->currentModulePath = $modulePath = APP_BASE_PATH . DS . $modules[$module]; } elseif (isset($modules[ucfirst(strtolower($module))]) && is_dir(APP_BASE_PATH . DS . $modules[ucfirst(strtolower($module))])) { // check case sensitivity $nameSpace = '\\' . ucfirst(strtolower($module)); $this->currentModulePath = $modulePath = APP_BASE_PATH . DS . $modules[ucfirst(strtolower($module))]; } else { return $this->getErrorMessage($module . ' module or path are not exist'); } // Controller Class Name $moduleController = ucfirst(strtolower($controller)) . 'Controller'; $controllerFile = $modulePath . DS . 'Commands' . DS . $moduleController . '.php'; $this->currentController = $controller; if (!file_exists($controllerFile)) { return $this->getErrorMessage($modulePath . DS . 'Commands' . DS . $moduleController . ' controller file is not exist'); } include $controllerFile; // controller class $controllerClass = $nameSpace . '\\Commands\\' . $moduleController; if (!class_exists($controllerClass)) { return $this->getErrorMessage($controllerClass . ' Controller Class is not exist'); } $moduleControllerObject = new $controllerClass(); $actionMethod = strtolower($action) . 'Action'; if (!method_exists($moduleControllerObject, $actionMethod)) { return $this->getErrorMessage($actionMethod . ' Action Method is not exist in Controller Class'); } return $moduleControllerObject->{$actionMethod}(); }
/** * Dispatch */ public function dispatch() { // check request and set params $uri = Safan::handler()->getObjectManager()->get('request')->getUri(); Safan::handler()->getObjectManager()->get('router')->checkUri($uri); $module = Get::exists('module'); $controller = Get::exists('controller'); $action = Get::exists('action'); if (!$module) { return $this->dispatchToError(404, 'Module Global Variable is not exists'); } if (!$controller) { return $this->dispatchToError(404, 'Controller Global Variable is not exists'); } if (!$action) { return $this->dispatchToError(404, 'Action Global Variable is not exists'); } $this->loadModule($module, $controller, $action); }