/**
  * 
  * @param string $psVar
  * @param string $pmDefault
  * @param bool $pbRequired
  * @return string
  */
 public function getRequestArg($psVar, $pmDefault = null, $pbRequired = false)
 {
     if (isset($this->_aParams['ARG'][$psVar])) {
         return $this->_aParams['ARG'][$psVar];
     } else {
         if (PHP_SAPI == "cli" && PROMPT) {
             $lsMsgHelp = "";
             $lsMsgHelpSeparate = "";
             $loHelp = new Help();
             $loHelp->factory($this->_sConfigPath);
             $lsVarHelp = $loHelp->getParamHelp($this->_sModule, $this->_sController, $this->_sAction, $psVar);
             if (!empty($lsVarHelp)) {
                 $lsMsgHelp = $lsVarHelp;
                 $lsMsgHelpSeparate = ". ";
             }
             if ($pmDefault != null) {
                 $lsMsgHelp .= "{$lsMsgHelpSeparate}Default: ({$pmDefault})";
                 $lsMsgHelpSeparate = ". ";
             }
             if ($pbRequired) {
                 $lsMsgHelp .= "{$lsMsgHelpSeparate}[required]";
             }
             if (!empty($lsMsgHelp)) {
                 echo "{$lsMsgHelp}\n";
             }
             $lsAnswer = System::prompt("Enter param [{$psVar}]:");
             if ($this->validateValue($psVar, $lsAnswer, 'ARG')) {
                 $this->_aParams['ARG'][$psVar] = $lsAnswer;
                 if (!empty($lsAnswer)) {
                     return $lsAnswer;
                 } elseif (!empty($pmDefault)) {
                     $this->_aParams['ARG'][$psVar] = $pmDefault;
                     return $pmDefault;
                 } elseif (!$pbRequired) {
                     return null;
                 } else {
                     System::echoError("The param value is required to continue!");
                     System::echoError("Try --help!");
                     System::exitError("ABORTING SCRIPT EXECUTION!");
                 }
             } else {
                 if (empty($lsAnswer) && !empty($pmDefault)) {
                     $this->_aParams['ARG'][$psVar] = $pmDefault;
                     return $pmDefault;
                 } elseif (empty($lsAnswer) && empty($pmDefault) && !$pbRequired) {
                     return null;
                 } else {
                     System::echoError("The param value do not match to the expected!");
                     System::echoError("Try --help!");
                     System::exitError("ABORTING SCRIPT EXECUTION!");
                 }
             }
         } else {
             return $pmDefault;
         }
     }
 }
Exemple #2
0
 /**
  * 
  */
 public function newServiceAction()
 {
     $this->setClientFolder($this->getRequestArg('folder', "onionapp.com"));
     $this->setModuleName($this->getRequestArg('service', null, true));
     if ($this->_sModuleName == null) {
         System::echoError("The param service is required! Please, use --help for further information.");
         return;
     }
     $lsPathClient = $this->_sClientPath;
     $lsPathService = $lsPathClient . DS . 'service';
     $lsPathConfig = $lsPathClient . DS . 'config';
     if (file_exists($lsPathService)) {
         $lsPathModule = $lsPathService . DS . $this->_sModuleName;
         $this->createDir($lsPathModule);
         if (file_exists($lsPathModule)) {
             $lsFileLicense = $this->getLicense($this->_sModuleName);
             $lsPathModuleConfig = $lsPathModule . DS . 'config';
             $this->createDir($lsPathModuleConfig);
             $this->saveFile($lsPathModuleConfig, 'help');
             $lsPathSrc = $lsPathModule . DS . 'src';
             $this->createDir($lsPathSrc);
             if (file_exists($lsPathSrc)) {
                 $lsPathSrcModule = $lsPathSrc . DS . $this->_sModuleName;
                 $this->createDir($lsPathSrcModule);
                 if (file_exists($lsPathSrcModule)) {
                     $lsPathController = $lsPathSrcModule . DS . 'Controller';
                     $this->createDir($lsPathController);
                     $this->saveFile($lsPathController, '_Controller', $lsFileLicense);
                     $lsPathEntity = $lsPathSrcModule . DS . 'Entity';
                     $this->createDir($lsPathEntity);
                     $this->saveFile($lsPathEntity, 'Entity', $lsFileLicense);
                     $lsPathRepository = $lsPathSrcModule . DS . 'Repository';
                     $this->createDir($lsPathRepository);
                     $this->saveFile($lsPathRepository, '_Repository', $lsFileLicense);
                     $lsPathView = $lsPathSrcModule . DS . 'View';
                     $this->createDir($lsPathView);
                     $lsPathViewController = $lsPathView . DS . $this->_sModuleName;
                     $this->createDir($lsPathViewController);
                     $this->setSrvModuleAutoload($lsPathConfig);
                 }
             }
         }
     } else {
         System::exitError("Client folder do not exist! You need to create a new client first. Please, use --help for further information.");
     }
 }
Exemple #3
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!");
     }
 }