Beispiel #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);
         }
     }
 }
Beispiel #2
0
 /**
  * 
  * @param string $psPath
  * @param string $psFile
  * @param string $psFileLicense
  * @param string $psFileType
  */
 public function saveFile($psPath, $psFile, $psFileLicense = "", $psFileType = "php")
 {
     switch ($psFile) {
         case 'htaccess':
             $lsFileName = ".{$psFile}";
             break;
         case 'Entity':
         case 'EntityEmpty':
             $lsFileName = "{$this->_sModuleName}.php";
             break;
         case 'actionIndex':
             $lsFileName = "index.phtml";
             break;
         case '_Dashboard':
         case '_Site':
             $lsFileName = "{$this->_sModuleName}Controller.php";
             break;
         case 'dashboard.config':
         case 'site.config':
             $lsFileName = "module.config.php";
             break;
         default:
             $lsFileName = "{$psFile}.{$psFileType}";
             $lsFileName = preg_replace("/_/", $this->_sModuleName, $lsFileName);
     }
     $lsFilePath = $psPath . DS . $lsFileName;
     if (!file_exists($lsFilePath)) {
         $lsFileContent = System::localRequest($this->_sModelPath . DS . "{$psFile}.model");
         Util::parse($lsFileContent, "#%LICENSE%#", $psFileLicense);
         Util::parse($lsFileContent, "#%MODULE%#", $this->_sModuleName);
         Util::parse($lsFileContent, "#%TABLE%#", $this->_sModuleName);
         Util::parse($lsFileContent, "#%ACTION%#", String::lcfirst($this->_sModuleName));
         Util::parse($lsFileContent, "#%ROUTE%#", String::slugfy($this->_sModuleName));
         Util::parse($lsFileContent, "#%PACKAGE%#", $this->_sClientFolder);
         Util::parse($lsFileContent, "#%CLIENT-NAME%#", $this->_sClientName);
         Util::parse($lsFileContent, "#%DATE%#", date('Y-m-d'));
         Util::parse($lsFileContent, "#%DOMAIN%#", $this->_sClientDomain);
         System::saveFile($lsFilePath, $lsFileContent);
     }
 }