Controller.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 刘志淳 <chun@engineer.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\console\command\make;
  12. use think\console\command\Make;
  13. use think\console\input\Option;
  14. use think\facade\Config;
  15. class Controller extends Make
  16. {
  17. protected $type = "Controller";
  18. protected function configure()
  19. {
  20. parent::configure();
  21. $this->setName('make:controller')
  22. ->addOption('api', null, Option::VALUE_NONE, 'Generate an api controller class.')
  23. ->addOption('plain', null, Option::VALUE_NONE, 'Generate an empty controller class.')
  24. ->setDescription('Create a new resource controller class');
  25. }
  26. protected function getStub()
  27. {
  28. $stubPath = __DIR__ . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR;
  29. if ($this->input->getOption('api')) {
  30. return $stubPath . 'controller.api.stub';
  31. }
  32. if ($this->input->getOption('plain')) {
  33. return $stubPath . 'controller.plain.stub';
  34. }
  35. return $stubPath . 'controller.stub';
  36. }
  37. protected function getClassName($name)
  38. {
  39. return parent::getClassName($name) . (Config::get('controller_suffix') ? ucfirst(Config::get('url_controller_layer')) : '');
  40. }
  41. protected function getNamespace($appNamespace, $module)
  42. {
  43. return parent::getNamespace($appNamespace, $module) . '\controller';
  44. }
  45. }