mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-02 11:48:08 +08:00
feat: Generate class command (#6158)
This commit is contained in:
parent
28c74a1b96
commit
618424564b
@ -29,6 +29,9 @@ return [
|
||||
'aspect' => [
|
||||
'namespace' => 'App\\Aspect',
|
||||
],
|
||||
'class' => [
|
||||
'namespace' => 'App',
|
||||
],
|
||||
'command' => [
|
||||
'namespace' => 'App\\Command',
|
||||
],
|
||||
|
40
src/devtool/src/Generator/ClassCommand.php
Normal file
40
src/devtool/src/Generator/ClassCommand.php
Normal file
@ -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
src/devtool/src/Generator/stubs/class.stub
Normal file
10
src/devtool/src/Generator/stubs/class.stub
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace %NAMESPACE%;
|
||||
|
||||
class %CLASS%
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user