Commit cce1eccc by 王召彬

Merge branch 'master' of http://139.199.22.180/tencent/services

parents 55871ccf ded3eaf0
......@@ -12,10 +12,10 @@ use Hdll\Services\Common\Exception\CommonException;
/**
* @Bean()
* Class {className}
* Class {daoName}
* @package App\Models\Dao
*/
class {className}
class {daoName}
{
public function create(array $info) : {entityName}
......
......@@ -30,7 +30,7 @@ class GenerateCommand
*
* @Options
* -n,--n the dao name
* -e,--e the entity name
* -en,--en the entity name
*
* @Example
* php swoft generate:dao -e entityName [-n daoName]
......@@ -83,9 +83,23 @@ class GenerateCommand
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$templatePath = $appPath.'/Commands/Common/ClassTemplate/Data/ClassTemplate';
$content = file_get_contents($templatePath);
$content = str_replace('{dataName}', $dataName, $content);
$content = str_replace("{daoName}", $daoName, $content);
$content = str_replace("{varDaoName}", lcfirst($daoName), $content);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
}
$dataPath = file_exists($dataPath)?$dataPath.'.gen':$dataPath;
file_put_contents($dataPath, $content);
......@@ -109,12 +123,50 @@ class GenerateCommand
$content = file_get_contents($templatePath);
$content = str_replace("{className}", $daoName,$content);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
$content = str_replace("{entityName}", $entityName, $content);
$content = str_replace("{varEntityName}", lcfirst($entityName), $content);
}
$daoPath = file_exists($daoPath)?$daoPath.'.gen':$daoPath;
file_put_contents($daoPath,$content);
}
/**
* 解析模板中变量
*
* @param string $content
* @return string
*/
private function parseVar(string $content):string
{
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$vars = isset($vars[0])?$vars[0]:[];
foreach ( $vars as $var ) {
if ( strpos($var, 'var') !== false ) {
$name = str_replace('var', '', $var);
$name = lcfirst($name);
$$var = lcfirst($$name);
var_dump($var, $$var);
}
$content = str_replace("{{$var}}", $$var,$content);
}
return $content;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment