public function makeTableFiles($dbname, $targetTable) { $_ = $this; if (!($DB = $_->getDB($dbname))) { die("error: '{$dbname}' class file is not exists in ../model/db/\n"); } $DbOperator = new DbOperatorContext($DB::$SYSTEM); $DbOperator->setDb($DB); $tables = $DbOperator->getTables(); $template = $DbOperator->getTableClassTemplate(); $columnTypes = $DbOperator->getColumnTypes(); $dirPath = $_->APP_ROOT . "/model/_def/db/{$dbname}"; if (!file_exists($dirPath)) { mkdir($dirPath, 0777, true); } $id_column = 'id'; // default foreach ($tables as $table) { if (!empty($targetTable) && $table != $targetTable) { continue; } $filePath = $dirPath . "/{$table}.php"; if (file_exists($filePath)) { echo "error: {$filePath} is exists. can not save file.\n\n"; continue; } $columns = $DbOperator->getColumns($table); foreach ($columns as $key => $column) { if ($column['extra'] == 'auto_increment') { $id_column = $column['name']; } foreach ($columnTypes as $mysqlType => $datatype) { if (preg_match("/^{$mysqlType}/", $column['type'])) { $columns[$key]['type'] = $datatype; break; } } } $_->view->assign('table', $table); $_->view->assign('id_column', $id_column); $_->view->assign('columns', $columns); $classCode = $_->view->fetch("string:{$template}"); file_put_contents($filePath, $classCode); echo "------------------------------\n"; echo "save class file {$table}.php\n"; echo "\n"; //echo $classCode; //echo "\n"; } }
public function makeTableModels($dbname, $targetTable) { $_ = $this; if (!($DB = $_->getDB($dbname))) { die("error: '{$dbname}' class file is not exists in ../model/db/\n"); } $DbOperator = new DbOperatorContext($DB::$SYSTEM); $DbOperator->setDb($DB); $tables = $DbOperator->getTables(); foreach ($tables as $table) { if (!empty($targetTable) && $table != $targetTable) { continue; } $dirPath = $_->APP_ROOT . "/model/{$table}"; if (!file_exists($dirPath)) { mkdir($dirPath, 0777, true); } $testDirPath = $_->APP_ROOT . "/test/model/{$table}"; if (!file_exists($testDirPath)) { mkdir($testDirPath, 0777, true); } // // List Model $columns = $DbOperator->getColumns($table); $_->view->assign('db', $dbname); $_->view->assign('table', $table); $_->view->assign('columns', $columns); $className = ucfirst($table) . 'List'; $_->view->assign('className', $className); $filePath = $dirPath . '/' . $className . ".php"; if (file_exists($filePath)) { echo "error: {$filePath} is exists. can not save file.\n\n"; } else { $templateFile = $_->APP_ROOT . '/etc/template/model/dataList.php'; $classCode = $_->view->fetch($templateFile); file_put_contents($filePath, $classCode); echo "------------------------------\n"; echo "save class file {$className}.php\n"; echo "\n"; //echo $classCode; //echo "\n"; } // List Model Test $filePath = $testDirPath . '/' . $className . "Test.php"; if (file_exists($filePath)) { echo "error: {$filePath} is exists. can not save file.\n\n"; } else { $templateFile = $_->APP_ROOT . '/etc/template/test/model/dataListTest.php'; $classCode = $_->view->fetch($templateFile); file_put_contents($filePath, $classCode); echo "------------------------------\n"; echo "save class file {$className}" . "Test.php\n"; echo "\n"; //echo $classCode; //echo "\n"; } // Record Model $className = ucfirst($table) . 'Record'; $_->view->assign('className', $className); $filePath = $dirPath . '/' . $className . ".php"; if (file_exists($filePath)) { echo "error: {$filePath} is exists. can not save file.\n\n"; } else { $templateFile = $_->APP_ROOT . '/etc/template/model/dataRecord.php'; $classCode = $_->view->fetch($templateFile); file_put_contents($filePath, $classCode); echo "------------------------------\n"; echo "save class file {$className}.php\n"; echo "\n"; //echo $classCode; //echo "\n"; } // Record Model Test $filePath = $testDirPath . '/' . $className . "Test.php"; if (file_exists($filePath)) { echo "error: {$filePath} is exists. can not save file.\n\n"; } else { $templateFile = $_->APP_ROOT . '/etc/template/test/model/dataRecordTest.php'; $classCode = $_->view->fetch($templateFile); file_put_contents($filePath, $classCode); echo "------------------------------\n"; echo "save class file {$className}" . "Test.php\n"; echo "\n"; //echo $classCode; //echo "\n"; } } }