Skip to content

Commit

Permalink
feat: Generate class command (#6158)
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Sep 19, 2023
1 parent 78667bb commit eb3af1d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions publish/devtool.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
'aspect' => [
'namespace' => 'App\\Aspect',
],
'class' => [
'namespace' => 'App',
],
'command' => [
'namespace' => 'App\\Command',
],
Expand Down
40 changes: 40 additions & 0 deletions src/Generator/ClassCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Devtool\Generator;

use Hyperf\Command\Annotation\Command;

#[Command]
class ClassCommand extends GeneratorCommand
{
public function __construct()
{
parent::__construct('gen:class');
}

public function configure()
{
$this->setDescription('Create a new class');

parent::configure();
}

protected function getStub(): string
{
return $this->getConfig()['stub'] ?? __DIR__ . '/stubs/class.stub';
}

protected function getDefaultNamespace(): string
{
return $this->getConfig()['namespace'] ?? 'App';
}
}
10 changes: 10 additions & 0 deletions src/Generator/stubs/class.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace %NAMESPACE%;

class %CLASS%
{

}

0 comments on commit eb3af1d

Please sign in to comment.