Skip to content

Commit eb3af1d

Browse files
feat: Generate class command (#6158)
1 parent 78667bb commit eb3af1d

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

publish/devtool.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
'aspect' => [
3030
'namespace' => 'App\\Aspect',
3131
],
32+
'class' => [
33+
'namespace' => 'App',
34+
],
3235
'command' => [
3336
'namespace' => 'App\\Command',
3437
],

src/Generator/ClassCommand.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of Hyperf.
6+
*
7+
* @link https://www.hyperf.io
8+
* @document https://hyperf.wiki
9+
* @contact [email protected]
10+
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+
*/
12+
namespace Hyperf\Devtool\Generator;
13+
14+
use Hyperf\Command\Annotation\Command;
15+
16+
#[Command]
17+
class ClassCommand extends GeneratorCommand
18+
{
19+
public function __construct()
20+
{
21+
parent::__construct('gen:class');
22+
}
23+
24+
public function configure()
25+
{
26+
$this->setDescription('Create a new class');
27+
28+
parent::configure();
29+
}
30+
31+
protected function getStub(): string
32+
{
33+
return $this->getConfig()['stub'] ?? __DIR__ . '/stubs/class.stub';
34+
}
35+
36+
protected function getDefaultNamespace(): string
37+
{
38+
return $this->getConfig()['namespace'] ?? 'App';
39+
}
40+
}

src/Generator/stubs/class.stub

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace %NAMESPACE%;
6+
7+
class %CLASS%
8+
{
9+
10+
}

0 commit comments

Comments
 (0)