初始化项目
This commit is contained in:
95
core/library/think/console/command/make/Controller.php
Normal file
95
core/library/think/console/command/make/Controller.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 刘志淳 <chun@engineer.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\console\command\make;
|
||||
|
||||
use think\App;
|
||||
use think\console\Input;
|
||||
use think\console\input\Argument;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
|
||||
class Controller extends \think\console\command\Make
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('make:controller')
|
||||
->setDescription('Create a new controller class')
|
||||
->addArgument('namespace', Argument::OPTIONAL, null)
|
||||
->addOption('module', 'm', Option::VALUE_OPTIONAL, 'Module Name', null)
|
||||
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Base on Controller class', null);
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$namespace = $input->getArgument('namespace');
|
||||
$module = $input->getOption('module');
|
||||
|
||||
|
||||
// 处理命名空间
|
||||
if (!empty($module)) {
|
||||
$namespace = App::$namespace . "\\" . $module . "\\" . 'controller' . "\\" . $namespace;
|
||||
}
|
||||
|
||||
// 处理继承
|
||||
$extend = $input->getOption('extend');
|
||||
|
||||
if (empty($extend)) {
|
||||
$extend = "\\think\\Controller";
|
||||
} else {
|
||||
if (!preg_match("/\\\/", $extend)) {
|
||||
if (!empty($module)) {
|
||||
$extend = "\\" . App::$namespace . "\\" . $module . "\\" . 'controller' . "\\" . $extend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$result = $this->build($namespace, $extend);
|
||||
$output->writeln("output:" . $result);
|
||||
}
|
||||
|
||||
private function build($namespace, $extend)
|
||||
{
|
||||
$tpl = file_get_contents(THINK_PATH . 'tpl' . DS . 'make_controller.tpl');
|
||||
|
||||
// comminute namespace
|
||||
$allNamespace = self::formatNameSpace($namespace);
|
||||
$namespace = implode('\\', $allNamespace[0]);
|
||||
$className = ucwords($allNamespace[1]);
|
||||
|
||||
// 处理内容
|
||||
$content = str_replace("{%extend%}", $extend,
|
||||
str_replace("{%className%}", $className,
|
||||
str_replace("{%namespace%}", $namespace, $tpl)
|
||||
)
|
||||
);
|
||||
|
||||
// 处理文件夹
|
||||
$path = '';
|
||||
foreach ($allNamespace[0] as $key => $value) {
|
||||
if ($key >= 1) {
|
||||
self::buildDir($path . $value);
|
||||
$path .= $value . "\\";
|
||||
}
|
||||
}
|
||||
|
||||
// 处理文件
|
||||
$file = $path . $className . '.php';
|
||||
self::buildFile($file, $content);
|
||||
|
||||
return APP_PATH . $file;
|
||||
}
|
||||
}
|
||||
26
core/library/think/console/command/make/Model.php
Normal file
26
core/library/think/console/command/make/Model.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\console\command\make;
|
||||
|
||||
|
||||
use think\console\command\Command;
|
||||
|
||||
|
||||
class Model extends Command
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct("make:model");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user