Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
cce1eccc
Commit
cce1eccc
authored
Oct 21, 2018
by
王召彬
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://139.199.22.180/tencent/services
parents
55871ccf
ded3eaf0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
9 deletions
+62
-9
src/Commands/ClassTemplate/Dao/ClassTemplate
+2
-2
src/Commands/GenerateCommand
+60
-7
No files found.
src/Commands/ClassTemplate/Dao/ClassTemplate
View file @
cce1eccc
...
@@ -12,10 +12,10 @@ use Hdll\Services\Common\Exception\CommonException;
...
@@ -12,10 +12,10 @@ use Hdll\Services\Common\Exception\CommonException;
/**
/**
* @Bean()
* @Bean()
* Class {
class
Name}
* Class {
dao
Name}
* @package App\Models\Dao
* @package App\Models\Dao
*/
*/
class {
class
Name}
class {
dao
Name}
{
{
public function create(array $info) : {entityName}
public function create(array $info) : {entityName}
...
...
src/Commands/GenerateCommand
View file @
cce1eccc
...
@@ -30,7 +30,7 @@ class GenerateCommand
...
@@ -30,7 +30,7 @@ class GenerateCommand
*
*
* @Options
* @Options
* -n,--n the dao name
* -n,--n the dao name
* -e
,--e
the entity name
* -e
n,--en
the entity name
*
*
* @Example
* @Example
* php swoft generate:dao -e entityName [-n daoName]
* php swoft generate:dao -e entityName [-n daoName]
...
@@ -83,9 +83,23 @@ class GenerateCommand
...
@@ -83,9 +83,23 @@ class GenerateCommand
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$templatePath = $appPath.'/Commands/Common/ClassTemplate/Data/ClassTemplate';
$templatePath = $appPath.'/Commands/Common/ClassTemplate/Data/ClassTemplate';
$content = file_get_contents($templatePath);
$content = file_get_contents($templatePath);
$content = str_replace('{dataName}', $dataName, $content);
$content = str_replace("{daoName}", $daoName, $content);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
$content = str_replace("{varDaoName}", lcfirst($daoName), $content);
$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);
file_put_contents($dataPath, $content);
...
@@ -109,12 +123,50 @@ class GenerateCommand
...
@@ -109,12 +123,50 @@ class GenerateCommand
$content = file_get_contents($templatePath);
$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("{entityName}", $entityName, $content);
$content = str_replace("{{$var}}", $$var,$content);
$content = str_replace("{varEntityName}", lcfirst($entityName), $content);
}
$daoPath = file_exists($daoPath)?$daoPath.'.gen':$daoPath;
file_put_contents($daoPath,$content);
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment