/** * 创建迁移 */ public function actCreate() { $request = \H2O::getContainer('request'); //控制台请求 $params = $request->getParams(); $name = isset($params['name']) ? $params['name'] : 'crt' . date('YmdHis'); $name = ucfirst($name); $mfile = $this->_migratedir . DS . $name . '.php'; if (file_exists($mfile)) { //文件已存在,提示 echo $mfile . ' is exist!' . PHP_EOL; exit; } $oimg = new \H2O\coding\Image(); if ($name == 'All') { //全量模板 $oimg->file('migrate/all.php', $mfile, ['search' => ['T_NAMESPACE', 'T_CLASS'], 'replace' => [substr($this->_namespace, 1), $name]]); } else { //普通通用模型 $oimg->file('migrate/general.php', $mfile, ['search' => ['T_NAMESPACE', 'T_CLASS'], 'replace' => [substr($this->_namespace, 1), $name]]); } echo 'Migrate application to create success!' . PHP_EOL; }
/** * 复制镜像 * @param $type 分类信息 controllers/models * @param $resource 源镜像文件 * @param $app 应用目录信息 name:应用名,path:应用路径 * @param $class 类名 * @param $conf 镜像配置信息 */ private function _copyImage($type, $resource, $app, $class, $conf = []) { $oimg = new \H2O\coding\Image(); $cfile = $app['path'] . DS . $type . DS . $class . '.php'; if (empty($conf)) { $conf = ['search' => [], 'replace' => []]; } $conf['search'][] = 'T_NAMESPACE'; //命名空间 $conf['search'][] = 'T_CLASS'; //类名 $conf['search'][] = 'T_MODEL_NAMESPACE'; //模型命名空间 $conf['replace'][] = ltrim(\H2O::APP_ROOT_NAME . '\\' . $app['name'] . '\\' . $type, '\\'); //类名 $conf['replace'][] = $class; //类名 $conf['replace'][] = ltrim(\H2O::APP_ROOT_NAME . '\\' . $app['name'] . '\\models', '\\'); //模型命名空间 return $oimg->file($resource, $cfile, $conf); }