代码优化

main
gzydong 2021-07-20 23:18:53 +08:00
parent 93131bde18
commit d2e58be344
4 changed files with 9 additions and 8 deletions

View File

@ -10,7 +10,7 @@
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Event\UserLogin; use App\Event\LoginEvent;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -60,7 +60,7 @@ class AuthController extends CController
return $this->response->error('登录异常,请稍后再试!'); return $this->response->error('登录异常,请稍后再试!');
} }
event()->dispatch(new UserLogin($this->request, $user)); event()->dispatch(new LoginEvent($this->request, $user));
return $this->response->success([ return $this->response->success([
'authorize' => [ 'authorize' => [

View File

@ -1,11 +1,12 @@
<?php <?php
declare(strict_types=1);
namespace App\Event; namespace App\Event;
use App\Model\User; use App\Model\User;
use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\RequestInterface;
class UserLogin class LoginEvent
{ {
/** /**
* @var User * @var User

View File

@ -10,7 +10,6 @@ class TalkEvent
*/ */
public $event_name; public $event_name;
/** /**
* @var array 消息数据 * @var array 消息数据
*/ */

View File

@ -1,26 +1,27 @@
<?php <?php
declare(strict_types=1);
namespace App\Listener; namespace App\Listener;
use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Event\Contract\ListenerInterface;
use App\Event\UserLogin; use App\Event\LoginEvent;
use Hyperf\Event\Annotation\Listener; use Hyperf\Event\Annotation\Listener;
/** /**
* @Listener * @Listener
*/ */
class UserLoginListener implements ListenerInterface class LoginListener implements ListenerInterface
{ {
public function listen(): array public function listen(): array
{ {
// 返回一个该监听器要监听的事件数组,可以同时监听多个事件 // 返回一个该监听器要监听的事件数组,可以同时监听多个事件
return [ return [
UserLogin::class, LoginEvent::class,
]; ];
} }
/** /**
* @param object|UserLogin $event * @param object|LoginEvent $event
*/ */
public function process(object $event) public function process(object $event)
{ {