Esempio n. 1
0
 /**
  * 
  * @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;
         }
     }
 }
Esempio n. 2
0
 /**
  * 
  * @param string $psService
  * @param string $psClass
  * @param string $psMethod
  * @param array $paParams
  * @return string
  */
 private static function run(array $paService, array $paParams)
 {
     global $gbHelp;
     //Verificando se o service existe
     if (file_exists($paService['service'])) {
         //Carregando o service
         include_once $paService['service'];
         //Verificando se a classe existe
         if (class_exists($paService['class'])) {
             //Criando o objeto da classe
             $loObj = new $paService['class']($paParams, $paService);
             if (is_object($loObj) && $loObj->_bHelp) {
                 return;
             }
             //Verificando se o objeto foi criado e se o metodo existe
             if (is_object($loObj) && method_exists($loObj, $paService['method'])) {
                 //Executando o metodo
                 $lmView = $loObj->{$paService}['method']();
                 if (method_exists($loObj, 'lineView')) {
                     $loObj->lineView($lmView);
                 }
             } else {
                 //Se o metodo não foi encontrado
                 System::exitError("Method not found!");
             }
         } else {
             //Se a classe não foi encontrada
             System::exitError("Class not found!");
         }
     } else {
         $loHelp = new Help();
         $loHelp->factory(dirname(dirname(dirname(dirname($paService['service'])))) . DS . 'config');
         $loHelp->setModuleHelp($loHelp->getModuleHelp($paService['module']));
         $loHelp->display();
     }
 }