Skip to content

Commit 4cf377a

Browse files
feat: add make:exception command
1 parent 5233740 commit 4cf377a

File tree

6 files changed

+130
-0
lines changed

6 files changed

+130
-0
lines changed

src/devtool/src/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Hypervel\Devtool\Generator\ConsoleCommand;
1414
use Hypervel\Devtool\Generator\ControllerCommand;
1515
use Hypervel\Devtool\Generator\EventCommand;
16+
use Hypervel\Devtool\Generator\ExceptionCommand;
1617
use Hypervel\Devtool\Generator\FactoryCommand;
1718
use Hypervel\Devtool\Generator\JobCommand;
1819
use Hypervel\Devtool\Generator\ListenerCommand;
@@ -70,6 +71,7 @@ public function __invoke(): array
7071
MiddlewareCommand::class,
7172
ControllerCommand::class,
7273
ResourceCommand::class,
74+
ExceptionCommand::class,
7375
],
7476
];
7577
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace %NAMESPACE%;
6+
7+
use Exception;
8+
use Hypervel\Http\Request;
9+
use Hypervel\Http\Response;
10+
11+
class %CLASS% extends Exception
12+
{
13+
/**
14+
* Report the exception.
15+
*/
16+
public function report(): void
17+
{
18+
//
19+
}
20+
21+
/**
22+
* Render the exception as an HTTP response.
23+
*/
24+
public function render(Request $request): Response
25+
{
26+
//
27+
}
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace %NAMESPACE%;
6+
7+
use Exception;
8+
use Hypervel\Http\Request;
9+
use Hypervel\Http\Response;
10+
11+
class %CLASS% extends Exception
12+
{
13+
/**
14+
* Render the exception as an HTTP response.
15+
*/
16+
public function render(Request $request): Response
17+
{
18+
//
19+
}
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace %NAMESPACE%;
6+
7+
use Exception;
8+
9+
class %CLASS% extends Exception
10+
{
11+
/**
12+
* Report the exception.
13+
*/
14+
public function report(): void
15+
{
16+
//
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace %NAMESPACE%;
6+
7+
use Exception;
8+
9+
class %CLASS% extends Exception
10+
{
11+
//
12+
}

0 commit comments

Comments
 (0)