Esempio n. 1
0
 /**
  * 
  */
 public function setEntityAction()
 {
     $this->setClientFolder($this->getRequestArg('folder', null, true));
     $this->setModuleName($this->getRequestArg('service', null, true));
     $lsDbPath = 'config' . DS . 'srv-service.php';
     $laDbClientConf = (require $this->_sClientPath . DS . $lsDbPath);
     $lsDbDriver = $this->getRequestArg('driver', $laDbClientConf['db']['driver']);
     $lsDbCharset = $this->getRequestArg('charset', $laDbClientConf['db']['charset']);
     $lsDbHost = $this->getRequestArg('host', $laDbClientConf['db']['hostname']);
     $lsDbPort = $this->getRequestArg('port', $laDbClientConf['db']['port']);
     $lsDbUser = $this->getRequestArg('user', $laDbClientConf['db']['username']);
     $lsDbPass = $this->getRequestArg('pass', $laDbClientConf['db']['password']);
     $lsDbName = $this->getRequestArg('dbname', $laDbClientConf['db']['database'], true);
     $laDbConf = array('driver' => $lsDbDriver, 'charset' => $lsDbCharset, 'hostname' => $lsDbHost, 'port' => $lsDbPort, 'username' => $lsDbUser, 'password' => $lsDbPass, 'database' => $lsDbName);
     $this->_aRepository['Db'] = new InstallRepository($laDbConf);
     if ($this->_aRepository['Db']->connect()) {
         $lsTableName = $this->getRequestArg('table', $this->_sModuleName, true);
         $laTable = $this->_aRepository['Db']->descEntity($lsTableName);
         if (is_array($laTable)) {
             $lsField = "";
             $lsData = "";
             foreach ($laTable as $laField) {
                 $lsF = $laField['Field'];
                 if ($lsF != 'id' && $lsF != 'User_id' && $lsF != 'dtInsert' && $lsF != 'dtUpdate' && $lsF != 'numStatus' && $lsF != 'isActive') {
                     $lsDefault = "";
                     $lsPri = "";
                     $lsPriORM = "";
                     $lsAuto = "";
                     $lsNull = '* @ORM\\Column(nullable=true)';
                     if ($laField['Default'] == '0' || !empty($laField['Default'])) {
                         $lsDefault = " = {$laField['Default']}";
                     }
                     if ($laField['Key'] == 'PRI') {
                         $lsPri = " PK";
                         $lsPriORM = "\n\t" . '* @ORM\\Id';
                     }
                     if ($laField['Extra'] == 'auto_increment') {
                         $lsAuto = "\n\t" . '* @ORM\\GeneratedValue(strategy="AUTO")';
                     }
                     if ($laField['Null'] == 'NO') {
                         $lsNull = '* @ORM\\Column(nullable=false)';
                     }
                     $laType = explode("(", $laField['Type']);
                     $lsType = $laType[0];
                     switch ($lsType) {
                         case 'int':
                         case 'tinyint':
                         case 'smallint':
                         case 'mediumint':
                         case 'bigint':
                             $lsFieldType = '* @var integer';
                             $lsFieldTypeORM = '* @ORM\\Column(type="integer")';
                             break;
                         case 'text':
                         case 'tinytext':
                         case 'mediumtext':
                         case 'longtext':
                         case 'blob':
                         case 'tinyblob':
                         case 'mediumblob':
                         case 'longblob':
                             $lsFieldType = '* @var text';
                             $lsFieldTypeORM = '* @ORM\\Column(type="text")';
                             break;
                         case 'date':
                         case 'time':
                         case 'timestamp':
                         case 'datetime':
                             $lsFieldType = '* @var datetime';
                             $lsFieldTypeORM = '* @ORM\\Column(type="datetime")';
                             break;
                         case 'decimal':
                         case 'float':
                         case 'double':
                         case 'real':
                             $lsFieldType = '* @var decimal';
                             $lsFieldTypeORM = '* @ORM\\Column(type="decimal")';
                             break;
                         case 'boolean':
                             $lsFieldType = '* @var boolean';
                             $lsFieldTypeORM = '* @ORM\\Column(type="boolean")';
                             break;
                         default:
                             $lsFieldType = '* @var string';
                             $lsFieldTypeORM = '* @ORM\\Column(type="string")';
                     }
                     $lsField .= "\t/**\n\t{$lsFieldType}{$lsPri}{$lsPriORM}{$lsAuto}\n\t{$lsFieldTypeORM}\n\t{$lsNull}*/\n\tprotected \${$laField['Field']}{$lsDefault};\n\n";
                 }
             }
             $lsPathSrcModule = $this->_sClientPath . DS . 'service' . DS . $this->_sModuleName . DS . 'src' . DS . $this->_sModuleName;
             $lsPathEntity = $lsPathSrcModule . DS . 'Entity' . DS . "{$lsTableName}.php";
             $lsFileContent = System::localRequest($lsPathEntity);
             if ($lsFileContent == false) {
                 $lsFileContent = System::localRequest($this->_sModelPath . DS . "Entity.model");
                 $lsFileLicense = $this->getLicense($this->_sModuleName);
                 Util::parse($lsFileContent, "#%LICENSE%#", $lsFileLicense);
                 Util::parse($lsFileContent, "#%MODULE%#", $this->_sModuleName);
                 Util::parse($lsFileContent, "#%TABLE%#", $lsTableName);
             }
             Util::parse($lsFileContent, "#%FIELDS%#", $lsField);
             System::saveFile($lsPathEntity, $lsFileContent);
         }
     }
 }
Esempio n. 2
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. 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!");
     }
 }
Esempio n. 4
0
 /**
  * 
  * @param string $psCommand
  * @return bool
  */
 public function checkCommandLine($psCommand)
 {
     $laCommandReturn = System::execute("command -v {$psCommand}");
     Debug::debug($laCommandReturn);
     if (is_array($laCommandReturn) && count($laCommandReturn) > 0) {
         return true;
     }
     return false;
 }
Esempio n. 5
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);
     }
 }