make指令更改为make:file

This commit is contained in:
thinkphp
2016-07-11 22:28:59 +08:00
parent 7718730600
commit a7b426e63a
3 changed files with 51 additions and 33 deletions

View File

@@ -49,8 +49,8 @@ class Console
"think\\console\\command\\Help",
"think\\console\\command\\Lists",
"think\\console\\command\\Build",
"think\\console\\command\\Make",
"think\\console\\command\\make\\Controller",
"think\\console\\command\\make\\File",
"think\\console\\command\\make\\Model",
"think\\console\\command\\optimize\\Autoload",
];

View File

@@ -12,46 +12,16 @@
namespace think\console\command;
use think\App;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\Exception;
class Make extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('make')
->setDescription('Create a new applcation class')
->addArgument('namespace', Argument::REQUIRED)
->addOption('layer', 'l', Option::VALUE_OPTIONAL, 'Layer Name', null)
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Extend Base class', null);
}
protected function execute(Input $input, Output $output)
{
$namespace = $input->getArgument('namespace');
$extend = $input->getOption('extend');
if (!$layer = $input->getOption('layer')) {
// 自动识别layer
$item = explode('\\', $namespace);
$layer = basename(dirname(implode(DS, $item)));
}
$result = $this->getResult($layer, $namespace, '', $extend);
$output->writeln("output:" . $result);
}
// 创建文件
protected static function buildFile($file, $content)
{
if (is_file($file)) {
exception('file already exists');
throw new Exception('file already exists');
}
if (!is_dir(dirname($file))) {

View File

@@ -0,0 +1,48 @@
<?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\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class File extends \think\console\command\Make
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('make:file')
->setDescription('Create a new applcation class')
->addArgument('namespace', Argument::REQUIRED)
->addOption('layer', 'l', Option::VALUE_OPTIONAL, 'Layer Name', null)
->addOption('extend', 'e', Option::VALUE_OPTIONAL, 'Extend Base class', null);
}
protected function execute(Input $input, Output $output)
{
$namespace = $input->getArgument('namespace');
$extend = $input->getOption('extend');
if (!$layer = $input->getOption('layer')) {
// 自动识别layer
$item = explode('\\', $namespace);
$layer = basename(dirname(implode(DS, $item)));
}
$result = $this->getResult($layer, $namespace, '', $extend);
$output->writeln("output:" . $result);
}
}