/** * 流程处理 * * @return boolean * @throws \Lib\Exception */ public function process() { if ($this->_state === false) { if (\Lib\Params::getInstance()->showHelp() === true) { $this->getHelp(); } return false; } $db = $this->getDbResponse(); $op = \Lib\Options::getInstance(); if (empty($this->_dbname)) { \Lib\State::error('The database is not specified'); } \Lib\State::notice('Scanning the database table...'); $tables = $op->getTable(); if (empty($tables)) { $tables = $db->findTables(); } else { foreach ($tables as $table) { if ($db->isExistTable($table) === false) { \Lib\State::warning('Unkown table \'' . $table . '\''); } } } if (empty($tables)) { \Lib\State::warning('Not found any tables'); } \Lib\State::notice('Found ' . sizeof($tables) . ' table(s)'); $modelFile = \Model\File::getInstance(); $modelContents = \Model\Content::getInstance(); $replaceArr = $op->getReplace() ?: []; foreach ($tables as $table) { $tableName = \Lib\Func::uc($table); $className = $tableName; if (!empty($replaceArr['source']) && !empty($replaceArr['target'])) { $className = str_ireplace($replaceArr['source'], ucfirst($replaceArr['target']), $className); } if (preg_match('/^[0-9]+/', $tableName)) { $tableName = ltrim(preg_replace('/^[0-9]+/', '', $tableName), '_'); } \Lib\State::notice('-----------------'); \Lib\State::notice('Processing [' . $table . ']'); $modelContents->setTableInfo($db->findTableInfo($table)); $modelContents->setClassName($className); $modelContents->setTableName($tableName); $modelContents->setColumns($db->findCols($table)); $modelContents->build(); \Lib\State::notice('Done'); $modelFile->setFileName($className)->build(); $modelContents->reset(); $modelFile->reset(); } return true; }