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
95bd7d78
Commit
95bd7d78
authored
Dec 29, 2018
by
feixiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: gen controller command
parent
126c8dda
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
8 deletions
+137
-8
src/Commands/Generate/.gitignore
+2
-0
src/Commands/Generate/ClassTemplate/Controller/classTemplate
+27
-0
src/Commands/Generate/ClassTemplate/Dao/ClassTemplate
+0
-0
src/Commands/Generate/ClassTemplate/Data/ClassTemplate
+0
-0
src/Commands/Generate/GenerateControlCommand
+95
-0
src/Commands/Generate/GenerateModelsCommand
+13
-8
No files found.
src/Commands/Generate/.gitignore
0 → 100644
View file @
95bd7d78
./*
\ No newline at end of file
src/Commands/Generate/ClassTemplate/Controller/classTemplate
0 → 100644
View file @
95bd7d78
<?php
namespace {{NAMESPACE}};
use Swoft\Http\Server\Bean\Annotation\Controller;
use Swoft\Http\Server\Bean\Annotation\RequestMapping;
use Swoft\Http\Server\Bean\Annotation\RequestMethod;
/**
* @Controller(prefix="")
*/
class {{CLASS_NAME}} extends BaseController
{
/**
* @RequestMapping(route="", method="")
*
* @return void
*/
public function index()
{
}
}
\ No newline at end of file
src/Commands/ClassTemplate/Dao/ClassTemplate
→
src/Commands/
Generate/
ClassTemplate/Dao/ClassTemplate
View file @
95bd7d78
File moved
src/Commands/ClassTemplate/Data/ClassTemplate
→
src/Commands/
Generate/
ClassTemplate/Data/ClassTemplate
View file @
95bd7d78
File moved
src/Commands/Generate/GenerateControlCommand
0 → 100644
View file @
95bd7d78
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace App\Commands\Common\Generate;
use Swoft\Console\Bean\Annotation\Command;
use Swoft\Console\Bean\Annotation\Mapping;
use Swoft\Console\Input\Input;
use Swoft\Console\Output\Output;
/**
* generate controller layer commands
*
* @Command(name="gen-control",coroutine=false)
*/
class GenerateControlCommand
{
private $templatesPath = "/Commands/Common/Generate/ClassTemplate";
/**
* this generate controller command
*
* @Usage
* generate:controller [options]
*
* @Options
* -c,--c the controller name with namespace
*
* @Example
* php swoft gen-control:controller -c "App\Controllers\V1\DemoController"
*
* @param Input $input
* @param Output $output
*
* @Mapping("controller")
*/
public function generateController(Input $input, Output $output)
{
$controllerName = $input->getOpt('c');
if (empty($controllerName)) {
$output->writeln("please input option -c", true, true);
}
$controllerParams = explode('\\', $controllerName);
$controllerDir = alias("@app");
$namespace = null;
$fileName = array_pop($controllerParams);
foreach( $controllerParams as $param ) {
if ($param == "App") {
$namespace = $param;
continue;
}
$controllerDir .= '/'.$param;
$namespace .= '\\'.$param;
}
if ( ! is_dir($controllerDir) ) {
mkdir($controllerDir, 0777);
}
$appPath = alias("@app");
$controllerPath = $controllerDir.'/'.$fileName.'.php';
$templateContent = file_get_contents($appPath . $this->templatesPath . '/Controller/classTemplate');
$templateContent = str_replace(
[
"{{NAMESPACE}}",
"{{CLASS_NAME}}"
],
[
$namespace,
ucfirst($fileName),
],
$templateContent
);
file_put_contents($controllerPath, $templateContent);
}
}
\ No newline at end of file
src/Commands/GenerateCommand
→
src/Commands/Generate
/GenerateModels
Command
View file @
95bd7d78
...
...
@@ -8,7 +8,7 @@
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace App\Commands\Common;
namespace App\Commands\Common
\Generate
;
use Swoft\Console\Bean\Annotation\Command;
use Swoft\Console\Bean\Annotation\Mapping;
...
...
@@ -18,11 +18,14 @@ use Swoft\Console\Output\Output;
/**
* generate dao,data layer commands
*
* @Command(coroutine=false)
* @Command(
name="gen-models",
coroutine=false)
*/
class GenerateCommand
class Generate
Models
Command
{
/**
private $templatesPath = "/Commands/Common/Generate/ClassTemplate";
/**
* this generate command
*
* @Usage
...
...
@@ -33,7 +36,7 @@ class GenerateCommand
* -en,--en the entity name
*
* @Example
* php swoft gen
erate
:dao -e entityName [-n daoName]
* php swoft gen
-models
:dao -e entityName [-n daoName]
*
* @param Input $input
* @param Output $output
...
...
@@ -59,7 +62,7 @@ class GenerateCommand
* -e,--e the entity name
*
* @Example
* php swoft gen
erate
:dao -e entityName [-n dataName] [--dao-name daoName]
* php swoft gen
-models
:dao -e entityName [-n dataName] [--dao-name daoName]
*
* @param Input $input
* @param Output $output
...
...
@@ -81,7 +84,7 @@ class GenerateCommand
//generateData
$dataPath = $appPath.'/Models/Data/'.$dataName.'.php';
$templatePath = $appPath
.'/Commands/Common/ClassTemplate
/Data/ClassTemplate';
$templatePath = $appPath
. $this->templatesPath.'
/Data/ClassTemplate';
$content = file_get_contents($templatePath);
preg_match_all('/(?<={)\w+(?=})/', $content, $vars);
...
...
@@ -119,7 +122,7 @@ class GenerateCommand
$daoPath = alias("@app").'/Models/Dao/'.$daoName.'.php';
$templatePath = alias("@app")
.'/Commands/Common/ClassTemplate
/Dao/ClassTemplate';
$templatePath = alias("@app")
. $this->templatesPath.'
/Dao/ClassTemplate';
$content = file_get_contents($templatePath);
...
...
@@ -169,4 +172,5 @@ class GenerateCommand
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