mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-04 06:30:53 +08:00
55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Events\NewsCreated;
|
|
use App\Events\TorrentCreated;
|
|
use App\Events\UserDestroyed;
|
|
use App\Events\UserDisabled;
|
|
use App\Events\UserEnabled;
|
|
use Illuminate\Console\Command;
|
|
|
|
class FireEvent extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'event:fire {--name=} {--id=}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Fire a event, options: --name, --id';
|
|
|
|
protected array $eventMaps = [
|
|
"torrent_created" => TorrentCreated::class,
|
|
"user_destroyed" => UserDestroyed::class,
|
|
"user_disabled" => UserDisabled::class,
|
|
"user_enabled" => UserEnabled::class,
|
|
"news_created" => NewsCreated::class,
|
|
];
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$name = $this->option('name');
|
|
$id = $this->option('id');
|
|
$log = "FireEvent, name: $name, id: $id";
|
|
if (isset($this->eventMaps[$name])) {
|
|
$result = call_user_func([$this->eventMaps[$name], "dispatch"], $id);
|
|
$this->info("$log, success call dispatch, result: " . var_export($result, true));
|
|
} else {
|
|
$this->error("$log, no event match this name");
|
|
}
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|