This commit is contained in:
49
app/Command/ServiceCommand.php
Normal file
49
app/Command/ServiceCommand.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\Devtool\Generator\GeneratorCommand;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
#[Command]
|
||||
class ServiceCommand extends GeneratorCommand
|
||||
{
|
||||
/**
|
||||
* 构造函数 生成指令
|
||||
* @param ContainerInterface $container
|
||||
*/
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('gen:service');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 stub 文件
|
||||
* @return string
|
||||
*/
|
||||
protected function getStub(): string
|
||||
{
|
||||
return __DIR__ . '/stubs/service.stub';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认命名空间
|
||||
* @return string
|
||||
*/
|
||||
protected function getDefaultNamespace(): string
|
||||
{
|
||||
return 'App\\Service';
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成逻辑
|
||||
* @return void
|
||||
*/
|
||||
public function configure(): void
|
||||
{
|
||||
$this->setDescription('Create a new service class');
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
}
|
||||
20
app/Command/stubs/service.stub
Normal file
20
app/Command/stubs/service.stub
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace %NAMESPACE%;
|
||||
|
||||
class %CLASS% extends
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user