|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hypervel\Devtool\Generator; |
| 6 | + |
| 7 | +use Hyperf\Devtool\Generator\GeneratorCommand; |
| 8 | +use Symfony\Component\Console\Input\InputOption; |
| 9 | + |
| 10 | +class ExceptionCommand extends GeneratorCommand |
| 11 | +{ |
| 12 | + public function __construct() |
| 13 | + { |
| 14 | + parent::__construct('make:exception'); |
| 15 | + } |
| 16 | + |
| 17 | + public function configure() |
| 18 | + { |
| 19 | + $this->setDescription('Create a new Exception class'); |
| 20 | + |
| 21 | + parent::configure(); |
| 22 | + } |
| 23 | + |
| 24 | + protected function getStub(): string |
| 25 | + { |
| 26 | + if ($this->input->getOption('render')) { |
| 27 | + $stub = $this->input->getOption('report') |
| 28 | + ? '/stubs/exception-render-report.stub' |
| 29 | + : '/stubs/exception-render.stub'; |
| 30 | + } else { |
| 31 | + $stub = $this->input->getOption('report') |
| 32 | + ? '/stubs/exception-report.stub' |
| 33 | + : '/stubs/exception.stub'; |
| 34 | + } |
| 35 | + return $this->getConfig()['stub'] ?? __DIR__ . $stub; |
| 36 | + } |
| 37 | + |
| 38 | + protected function getDefaultNamespace(): string |
| 39 | + { |
| 40 | + return $this->getConfig()['namespace'] ?? 'App\Exceptions'; |
| 41 | + } |
| 42 | + |
| 43 | + protected function getOptions(): array |
| 44 | + { |
| 45 | + return array_merge(parent::getOptions(), [ |
| 46 | + ['render', null, InputOption::VALUE_NONE, 'Create the exception with an empty render method'], |
| 47 | + ['report', null, InputOption::VALUE_NONE, 'Create the exception with an empty report method'], |
| 48 | + ]); |
| 49 | + } |
| 50 | +} |
0 commit comments