/** * @param $code * @param $message * @return mixed */ public function dispatchToError($code, $message) { if (Safan::handler()->getDebugMode()) { Safan::handler()->getObjectManager()->get('flashMessenger')->set('error', $message); } Safan::handler()->getObjectManager()->get('router')->checkUri('/' . $code); return $this->loadModule(Get::str('module'), Get::str('controller'), Get::str('action')); }
/** * @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}(); }