private function _makeDataArray($row) { $dataArray = []; foreach ($row as $keySnakeCase => $value) { $keyCamelCase = NamingConvention::snakeCaseToCamelCase($keySnakeCase); $definitions = $this->_structure[$keyCamelCase]; switch ($definitions[0]) { case TYPE_INT: case TYPE_PRIMARY: $dataArray[$keyCamelCase] = (int) $value; break; case TYPE_FLOAT: $dataArray[$keyCamelCase] = (double) $value; break; case TYPE_STRING: case TYPE_TEXT: case TYPE_DATE_TIME: case TYPE_DATE: case TYPE_TIME: $dataArray[$keyCamelCase] = stripslashes($value); break; default: $dataArray[$keyCamelCase] = stripslashes($value); break; } } return $dataArray; }
private function _createSQL() { $sql = 'INSERT INTO `' . $this->_tableName . '` ('; //Spalten-Namen hinzufuegen $count = 0; foreach ($this->_structure as $keyCamelCase => $definitions) { $sql .= ' `' . NamingConvention::camelCaseToSnakeCase($keyCamelCase) . '` '; if (++$count < count($this->_structure)) { $sql .= ', '; } } $sql .= ') VALUES ('; //Spaten-Werte hinzufuegen $count = 0; foreach ($this->_structure as $keyCamelCase => $definitions) { $value = $this->_getDatabaseObjectAttribte($keyCamelCase); $value = $this->_castValue($value, $definitions[0]); $sql .= $value; if (++$count < count($this->_structure)) { $sql .= ', '; } } $sql .= ')'; return $sql; }
private function _getStructureFromBaseRepoFile($fileName) { $objBaseRepositoryName = str_replace('.php', '', $fileName); $objBaseRepositoryName = NamingConvention::snakeCaseToCamelCaseFirstUpper($objBaseRepositoryName) . 'sitory'; load_file($this->_baseRepoDir . $fileName); $objRepository = new $objBaseRepositoryName(); return $objRepository->getStructure(); }
public function showDefaultEdit($objClassname, $columnNames) { $this->setTemplate($this->_standardTmpl); $this->loadTmplVar('CONTENT', '/app/tmpl/haml/public/default/new_edit.haml'); $this->addHamlVar('objClassname', $objClassname); $this->addHamlVar('moduleName', NamingConvention::camelCaseToSnakeCase($objClassname) . 's'); $this->addHamlVar('columnNames', $columnNames); $this->addHamlVar('submitvalue', 'Change'); $this->showTmpl(); }
public function createRepositoryFile($objName, $structure) { $repoFileName = NamingConvention::camelCaseToSnakeCase($objName) . '_repo.php'; $repoPath = ROOT . '/app/repository/' . $repoFileName; $repoTmpl = file_get_contents(ROOT . '/library/core/console/tmpl/obj_repo.tmpl'); $classNameSnakeCase = NamingConvention::camelCaseToSnakeCase($objName); $repoTmpl = str_replace('{CLASS_NAME_SNAKE_CASE}', $classNameSnakeCase, $repoTmpl); $repoTmpl = str_replace('{CLASS_NAME}', $objName, $repoTmpl); Debug::log('creating: ' . $repoPath); if (!file_exists($repoPath)) { file_put_contents($repoPath, $repoTmpl); } }
public function createModelControllerFile($objName, $app) { $app = ucfirst($app); if ($app == '') { $app = 'Public'; } $objName .= 's'; $controllerTmpl = file_get_contents(ROOT . '/library/core/console/tmpl/obj_controller.tmpl'); $controllerTmpl = str_replace('{CLASS_NAME}', $objName, $controllerTmpl); $controllerTmpl = str_replace('{APP}', $app, $controllerTmpl); $controllerName = NamingConvention::camelCaseToSnakeCase($objName) . '_' . lcfirst($app) . '.php'; $controllerPath = ROOT . '/app/controller/' . lcfirst($app) . '/' . $controllerName; Debug::out('create: ' . $controllerPath); file_put_contents($controllerPath, $controllerTmpl); }
private function _createSQL() { $sql = 'UPDATE `' . $this->_tableName . '` SET '; //Spalten-Namen hinzufuegen $count = 0; foreach ($this->_structure as $keyCamelCase => $definitions) { $value = $this->_getDatabaseObjectAttribte($keyCamelCase); $value = $this->_castValue($value, $definitions[0]); $sql .= ' `' . NamingConvention::camelCaseToSnakeCase($keyCamelCase) . '` = ' . $value; if (++$count < count($this->_structure)) { $sql .= ', '; } } $sql .= ' WHERE id = ' . (int) $this->_databaseObject->getId(); return $sql; }
private function _setFromArray($array, $setMethodName) { $arraKeyName = NamingConvention::camelCaseToSnakeCase($setMethodName); if (isset($array[lcfirst($arraKeyName)])) { $setMethod = 'set' . $setMethodName; $this->{$setMethod}(stripslashes($array[lcfirst($arraKeyName)])); } }
private function _createStrGetObjsFunction($objName, $dependency) { // Company:creatorId -> User:getCompanysAsCreator(); // Company:changerId -> User:getCompanysAsChanger(); // Company:userId -> User:getCompanys(); //varNameId -> VarName $foreignVarName = $dependency[1]; $foreignSqlVarName = NamingConvention::camelCaseToSnakeCase($foreignVarName); $foreignSqlVarNameSave = "'" . $foreignSqlVarName . "'"; $foreignVarObjName = substr($foreignVarName, 0, strlen($foreignVarName) - 2); $foreignVarObjName = ucfirst($foreignVarObjName); //Build functionname $foreignObjName = $dependency[0]; $functionName = $dependency[0] . 's'; if ($objName != $foreignVarObjName) { $functionName .= 'As' . $foreignVarObjName; } //Build Varname $varName = lcfirst($functionName); $name = substr($name, 0, strlen($name) - 2); $spaces = 4; $str .= $this->_writeLine('public function get' . $functionName . '($orderBy = null, $cache = true)', $spaces); $str .= $this->_writeLine('{', $spaces); $str .= $this->_writeLine(' if (!$this->_' . $varName . ' || $cache == false) {', $spaces); $str .= $this->_writeLine(' $repo = new ' . $foreignObjName . 'Repository();', $spaces); $str .= $this->_writeLine(' $repo->orderBy($orderBy);', $spaces); $str .= $this->_writeLine(' $this->_' . $varName . ' = $repo->getAllBy(' . $foreignSqlVarNameSave . ', $this->getId());', $spaces); $str .= $this->_writeLine(' }', $spaces); $str .= $this->_writeLine(' return $this->_' . $varName . ';', $spaces); $str .= $this->_writeLine('}', $spaces); return $str; }
private function _invoke($query) { $invokeFunction = 'invoke' . NamingConvention::snakeCaseToCamelCaseFirstUpper($query['action']); $classNameSnakeCase = $query['module'] . '_' . $query['app'] . '_controller'; $rc = new ReflectionClass(NamingConvention::snakeCaseToCamelCaseFirstUpper($classNameSnakeCase)); $controller = $rc->newInstance(); $hasFunction = false; $methods = get_class_methods($controller); foreach ($methods as $method) { if ($method == $invokeFunction) { $controller->{$invokeFunction}(); return true; } } return false; }
private function _getLabelText($varName, $inputName) { if ($inputName) { $name = $inputName; } else { $name = $varName; } $labelName = $this->_labels[$name]; if (!$labelName) { $labelName = NamingConvention::camelCaseToSnakeCase($varName); } return $labelName; }
private function _renameAttributeInModel($argv) { $objName = $argv[2]; $this->_checkObjectName($objName); $attNameOld = $argv[3]; $structureNew = $this->_parseStructure($argv, 4); $this->_checkStructure($structureNew); $attNameNew = key($structureNew); $definitionsNew = $structureNew[$attNameNew]; $objBaseRepositoryName = $objName . 'BaseRepository'; $objBaseRepositoryFileName = NamingConvention::camelCaseToSnakeCase($objName) . '_base_repo.php'; load_file($this->_baseRepoDir . $objBaseRepositoryFileName); $objRepository = new $objBaseRepositoryName(); $structure = $objRepository->getStructure(); $definitionsOld = $structure[$attNameOld]; unset($structure[$attNameOld]); $structure[$attNameNew] = $definitionsNew; $modelFileCreator = new ModelFileCreator(); $modelFileCreator->updateModelBaseFile($objName, $structure); $repositoryFileCreator = new RepositoryFileCreator(); $repositoryFileCreator->updateRepositoryBaseFile($objName, $structure); $migrationFileCreator = new MigrationFileCreator(); $migrationFileCreator->createMigrationRenameFile($objName, $attNameOld, $definitionsOld, $attNameNew, $definitionsNew); }
private static function _stdValuesToSnakeCase($values) { if ($values['app']) { $values['app'] = NamingConvention::camelCaseToSnakeCase($values['app']); } if ($values['module']) { $values['module'] = NamingConvention::camelCaseToSnakeCase($values['module']); } if ($values['action']) { $values['action'] = NamingConvention::camelCaseToSnakeCase($values['action']); } return $values; }
public function name($value) { $this->_attributes['name'] = NamingConvention::camelCaseToSnakeCase($value); }
private function _createStrMigrationAttribute($name, $definitions) { $type = $definitions[0]; $spaces = 12; $str .= $this->_writeLine("['" . NamingConvention::camelCaseToSnakeCase($name) . "', '" . $type . "']", $spaces, false); return $str; }
public function getTableName() { return NamingConvention::camelCaseToSnakeCase($this->_objName); }
private function _getActiveRecordClassName($activeRecordFileName) { $classNameSnakeCase = substr($activeRecordFileName, 15, strlen($activeRecordFileName) - (16 + 3)); $classNameCamelCase = NamingConvention::snakeCaseToCamelCaseFirstUpper($classNameSnakeCase); return $classNameCamelCase . 'Migration'; }