/** * DB関連のコマンドライン パラメータを返す */ public function getDbParams() { $_ = $this; $params = array(); if ($dbName = cmdLibs::getParam('-d')) { echo "use database : {$dbName}.\n"; $params['dbName'] = $dbName; if (!($systemName = cmdLibs::getParam('-s'))) { echo "Plaese set database system name.\n"; die($_->usage); } else { $systems = array('mysql', 'pgsql', 'sqlite'); $systemName = strtolower($systemName); if (in_array($systemName, $systems) !== false) { echo "use database system : {$systemName}.\n"; $params['systemName'] = $systemName; if ($systemName == 'sqlite') { if (!($dbDir = cmdLibs::getParam('-D'))) { echo "Plaese set database dir(from App Root).\n"; die($_->usage); } else { echo "use database file {$dbDir}\n"; $params['dbDir'] = $dbDir; } } else { if (!($userName = cmdLibs::getParam('-u'))) { echo "Plaese set database user name.\n"; die($_->usage); } else { echo "use database user: {$userName}.\n"; $params['userName'] = $userName; } if ($password = cmdLibs::getParam('-p')) { echo "use password for database.\n"; $params['password'] = $password; } else { echo "no password for database.\n"; $params['password'] = ''; } $params['dbDir'] = ''; } } else { echo "please set valid database system name" . " [mysql|pgsql|sqlite]\n"; die($_->usage); } } } return $params; }
public function main() { $_ = $this; $_->APP_ROOT = CmdLibs::getAppRoot(1); $_->initView(); $_->view->assign('localTestServer', $this->C['LOCAL_TEST_SERVER']); // パラメータからモデル名とページ名を決定。 $modelName = cmdLibs::getParam('-m'); $pageName = cmdLibs::getParam('-p'); $overWrite = cmdLibs::getParam('-o'); if (empty($modelName) && empty($pageName)) { die("usage: " . cmdLibs::scriptName() . " -m modelName -p pageName [-o yes]\n At least you should spec one parameter -m or -p.\n"); } if ($modelName) { echo "use model name {$modelName}.\n"; // テーブル名を取得 //$MODEL = $_->getModel($modelName); $MODEL = new $modelName(); $tableName = $MODEL->TABLE->TABLE; if (empty($tableName)) { die("\nmodel {$modelName} is not correct.\n\n"); } echo "table name is '{$tableName}'.\n"; // テーブルのカラム一覧を取得 $DB = $MODEL->DB; $DbOperator = new DbOperatorContext($DB::$SYSTEM); $DbOperator->setDb($DB); $columns = $DbOperator->getColumns($tableName); // モデル関連テンプレート変数の設定 $_->view->assign('modelName', $modelName); $_->view->assign('tableName', $tableName); $_->view->assign('columns', $columns); } // ページ名を決定 if (!$pageName) { if (preg_match("/(.*)List/", $modelName, $m)) { $pageName = lcfirst($m[1]); } elseif (preg_match("/(.*)Record/", $modelName, $m)) { $pageName = lcfirst($m[1]) . '/record'; } else { $pageName = $tableName; } } echo "page name is '{$pageName}'.\n"; // 上書きモードを設定 if ($overWrite == 'yes') { $_->overWrite = true; } else { $_->overWrite = false; } // ページ名からクラス名を生成 if (strpos($pageName, '/') !== false) { $pageNameAry = explode('/', $pageName); $pageNameAry = array_map("ucfirst", $pageNameAry); $className = implode('', $pageNameAry); } else { $className = ucfirst($pageName); } echo "class name is '{$className}'.\n\n"; // ページ関係テンプレート変数の設定 $_->view->assign('pageName', $pageName); $_->view->assign('className', $className); // 各ファイルの保存 if (isset($MODEL)) { switch ($MODEL::MODEL_TYPE) { case 'List': $_->genListCtl($pageName, $className); $_->genListHtml($pageName); $_->genAutoList($pageName); $_->genScrollAndSearch($pageName, $className); $_->genLangResource($pageName); $_->genListTest($pageName, $className); break; case 'Record': $_->genRecordCtl($pageName, $className); $_->genRecordHtml($pageName); $_->genAddHtml($pageName); $_->genEditHtml($pageName); $_->genAutoRecord($pageName); $_->genAutoAddForm($pageName); $_->genAutoEditForm($pageName); $_->genPost($pageName, $className); $_->genLangResource($pageName); $_->genRecordTest($pageName, $className); break; } } else { $_->genBlankCtl($pageName, $className); $_->genBlankHtml($pageName); $_->genLangResource($pageName); $_->genBlankTest($pageName, $className); } }