From a7b426e63ac08beed989fbcdb67144c5ed0d9fc2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 11 Jul 2016 22:28:59 +0800 Subject: [PATCH] =?UTF-8?q?make=E6=8C=87=E4=BB=A4=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E4=B8=BAmake:file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Console.php | 2 +- library/think/console/command/Make.php | 34 +-------------- library/think/console/command/make/File.php | 48 +++++++++++++++++++++ 3 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 library/think/console/command/make/File.php diff --git a/library/think/Console.php b/library/think/Console.php index 60cf15c2..d0b86193 100644 --- a/library/think/Console.php +++ b/library/think/Console.php @@ -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", ]; diff --git a/library/think/console/command/Make.php b/library/think/console/command/Make.php index 362bae23..a28cf0f0 100644 --- a/library/think/console/command/Make.php +++ b/library/think/console/command/Make.php @@ -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))) { diff --git a/library/think/console/command/make/File.php b/library/think/console/command/make/File.php new file mode 100644 index 00000000..146e0b51 --- /dev/null +++ b/library/think/console/command/make/File.php @@ -0,0 +1,48 @@ + +// +---------------------------------------------------------------------- + +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); + } + +}