feat: config
This commit is contained in:
35
app/Command/EventCommand.php
Normal file
35
app/Command/EventCommand.php
Normal 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';
|
||||
}
|
||||
}
|
||||
15
app/Command/stubs/event.stub
Normal file
15
app/Command/stubs/event.stub
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace %NAMESPACE%;
|
||||
|
||||
class %CLASS%
|
||||
{
|
||||
public $xxx;
|
||||
|
||||
public function __construct($xxx)
|
||||
{
|
||||
$this->xxx = $xxx;
|
||||
}
|
||||
}
|
||||
18
app/Event/RegistrationEvent.php
Normal file
18
app/Event/RegistrationEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
30
app/Listener/FirstRegistrationListener.php
Normal file
30
app/Listener/FirstRegistrationListener.php
Normal 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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
"hyperf/database": "~3.1.0",
|
||||
"hyperf/db-connection": "~3.1.0",
|
||||
"hyperf/engine": "^2.10",
|
||||
"hyperf/event": "^3.1",
|
||||
"hyperf/framework": "~3.1.0",
|
||||
"hyperf/guzzle": "~3.1.0",
|
||||
"hyperf/http-server": "~3.1.0",
|
||||
|
||||
Reference in New Issue
Block a user