feat: config

This commit is contained in:
2025-03-23 19:18:08 +08:00
parent 87a5b2f9e1
commit be26c85d82
5 changed files with 99 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Command;
use Hyperf\Command\Annotation\Command;
use Hyperf\Devtool\Generator\GeneratorCommand;
use Psr\Container\ContainerInterface;
#[Command]
class EventCommand extends GeneratorCommand
{
public function __construct(protected ContainerInterface $container)
{
parent::__construct('gen:event');
}
public function configure()
{
$this->setDescription('Create a new event class');
parent::configure();
}
protected function getStub(): string
{
return __DIR__ . '/stubs/event.stub';
}
protected function getDefaultNamespace(): string
{
return 'App\\Event';
}
}

View File

@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
namespace %NAMESPACE%;
class %CLASS%
{
public $xxx;
public function __construct($xxx)
{
$this->xxx = $xxx;
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Event;
class RegistrationEvent
{
public int $userId;
/**
* @param int $userId
*/
public function __construct(int $userId)
{
$this->userId = $userId;
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Listener;
use App\Event\RegistrationEvent;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;
#[Listener]
class FirstRegistrationListener implements ListenerInterface
{
public function __construct(protected ContainerInterface $container)
{
}
public function listen(): array
{
return [
// 注册事件
RegistrationEvent::class,
];
}
public function process(object $event): void
{
}
}

View File

@@ -25,6 +25,7 @@
"hyperf/database": "~3.1.0", "hyperf/database": "~3.1.0",
"hyperf/db-connection": "~3.1.0", "hyperf/db-connection": "~3.1.0",
"hyperf/engine": "^2.10", "hyperf/engine": "^2.10",
"hyperf/event": "^3.1",
"hyperf/framework": "~3.1.0", "hyperf/framework": "~3.1.0",
"hyperf/guzzle": "~3.1.0", "hyperf/guzzle": "~3.1.0",
"hyperf/http-server": "~3.1.0", "hyperf/http-server": "~3.1.0",