From 4620dbc52d0d779d3741ea3f79198fa66a286f97 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Fri, 23 Jul 2021 21:34:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Cache/Repository/AbstractRedis.php | 2 +- app/Controller/Api/V1/ContactsController.php | 4 +-- app/Controller/Api/V1/DownloadController.php | 2 +- app/Exception/Handler/AppExceptionHandler.php | 2 +- app/Process/RedisWebsocketSubscribe.php | 2 +- app/Service/ContactApplyService.php | 4 +-- .../Message/SubscribeHandleService.php | 4 +-- app/Service/SplitUploadService.php | 4 +-- app/Service/TalkListService.php | 4 +-- app/Service/TalkService.php | 8 +++--- app/Service/UserService.php | 4 +-- app/Support/MailerTemplate.php | 2 +- app/Support/SendEmailCode.php | 2 +- app/Support/UserRelation.php | 2 +- app/helper.php | 26 +++++++++---------- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/Cache/Repository/AbstractRedis.php b/app/Cache/Repository/AbstractRedis.php index e627a53..966364f 100644 --- a/app/Cache/Repository/AbstractRedis.php +++ b/app/Cache/Repository/AbstractRedis.php @@ -12,7 +12,7 @@ abstract class AbstractRedis public static function getInstance() { - return container()->get(static::class); + return di()->get(static::class); } /** diff --git a/app/Controller/Api/V1/ContactsController.php b/app/Controller/Api/V1/ContactsController.php index 8fc7a26..fe91d36 100644 --- a/app/Controller/Api/V1/ContactsController.php +++ b/app/Controller/Api/V1/ContactsController.php @@ -52,7 +52,7 @@ class ContactsController extends CController if ($rows) { $runArr = ServerRunID::getInstance()->getServerRunIdAll(); foreach ($rows as $k => $row) { - $rows[$k]['is_online'] = container()->get(SocketClientService::class)->isOnlineAll($row['id'], $runArr); + $rows[$k]['is_online'] = di()->get(SocketClientService::class)->isOnlineAll($row['id'], $runArr); } } @@ -77,7 +77,7 @@ class ContactsController extends CController return $this->response->fail('好友关系解除失败!'); } - container()->get(TalkListService::class)->deleteByType($user_id, $params['friend_id'], TalkModeConstant::PRIVATE_CHAT); + di()->get(TalkListService::class)->deleteByType($user_id, $params['friend_id'], TalkModeConstant::PRIVATE_CHAT); // TODO 推送消息(待完善) diff --git a/app/Controller/Api/V1/DownloadController.php b/app/Controller/Api/V1/DownloadController.php index e3388e5..4516a8a 100644 --- a/app/Controller/Api/V1/DownloadController.php +++ b/app/Controller/Api/V1/DownloadController.php @@ -33,7 +33,7 @@ class DownloadController extends CController { private function getFilePath(string $path) { - return container()->get(Filesystem::class)->getConfig()->get('root') . '/' . $path; + return di()->get(Filesystem::class)->getConfig()->get('root') . '/' . $path; } /** diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index c6b8b77..ea9554b 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -70,7 +70,7 @@ class AppExceptionHandler extends ExceptionHandler email()->send( $adminEmail, '系统报错通知', - container()->get(MailerTemplate::class)->errorNotice($throwable) + di()->get(MailerTemplate::class)->errorNotice($throwable) ); } catch (\Exception $exception) { diff --git a/app/Process/RedisWebsocketSubscribe.php b/app/Process/RedisWebsocketSubscribe.php index 893a269..ff33348 100644 --- a/app/Process/RedisWebsocketSubscribe.php +++ b/app/Process/RedisWebsocketSubscribe.php @@ -34,7 +34,7 @@ class RedisWebsocketSubscribe extends AbstractProcess */ public function handle(): void { - $this->handleService = container()->get(SubscribeHandleService::class); + $this->handleService = di()->get(SubscribeHandleService::class); redis()->subscribe($this->chans, [$this, 'subscribe']); } diff --git a/app/Service/ContactApplyService.php b/app/Service/ContactApplyService.php index 938ebd8..d305f44 100644 --- a/app/Service/ContactApplyService.php +++ b/app/Service/ContactApplyService.php @@ -47,7 +47,7 @@ class ContactApplyService FriendApply::getInstance()->incr($friend_id, 1); // 判断对方是否在线。如果在线发送消息通知 - $isOnline = container()->get(SocketClientService::class)->isOnlineAll($friend_id); + $isOnline = di()->get(SocketClientService::class)->isOnlineAll($friend_id); if ($isOnline) { event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [ 'apply_id' => $result->id, @@ -98,7 +98,7 @@ class ContactApplyService } // 判断对方是否在线。如果在线发送消息通知 - $isOnline = container()->get(SocketClientService::class)->isOnlineAll($info->user_id); + $isOnline = di()->get(SocketClientService::class)->isOnlineAll($info->user_id); if ($isOnline) { event()->dispatch(new TalkEvent(TalkEventConstant::EVENT_FRIEND_APPLY, [ 'apply_id' => $apply_id, diff --git a/app/Service/Message/SubscribeHandleService.php b/app/Service/Message/SubscribeHandleService.php index d1316eb..bb650ff 100644 --- a/app/Service/Message/SubscribeHandleService.php +++ b/app/Service/Message/SubscribeHandleService.php @@ -118,7 +118,7 @@ class SubscribeHandleService if (!$result) return; - $message = container()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0]; + $message = di()->get(FormatMessageService::class)->handleChatRecords([$result->toArray()])[0]; $notify = [ 'sender_id' => $sender_id, 'receiver_id' => $receiver_id, @@ -156,7 +156,7 @@ class SubscribeHandleService $fds = []; - $ids = container()->get(UserService::class)->getFriendIds($user_id); + $ids = di()->get(UserService::class)->getFriendIds($user_id); foreach ($ids as $friend_id) { $fds = array_merge($fds, $this->clientService->findUserFds(intval($friend_id))); } diff --git a/app/Service/SplitUploadService.php b/app/Service/SplitUploadService.php index c2effc6..45c57ce 100644 --- a/app/Service/SplitUploadService.php +++ b/app/Service/SplitUploadService.php @@ -68,7 +68,7 @@ class SplitUploadService $save_path = "tmp/{$hashName}/" . "{$hashName}_{$split_index}_{$fileInfo->file_ext}.tmp"; try { - container()->get(Filesystem::class)->write($save_path, file_get_contents($file->getRealPath())); + di()->get(Filesystem::class)->write($save_path, file_get_contents($file->getRealPath())); } catch (\Exception $e) { return false; } @@ -119,7 +119,7 @@ class SplitUploadService $file_merge = "tmp/{$hash_name}/{$fileInfo->original_name}.tmp"; - $filesystem = container()->get(Filesystem::class); + $filesystem = di()->get(Filesystem::class); $root_path = $filesystem->getConfig()->get('root'); foreach ($files as $file) { file_put_contents( diff --git a/app/Service/TalkListService.php b/app/Service/TalkListService.php index 883aa86..778918d 100644 --- a/app/Service/TalkListService.php +++ b/app/Service/TalkListService.php @@ -141,8 +141,8 @@ class TalkListService $data['name'] = $item['nickname']; $data['avatar'] = $item['user_avatar']; $data['unread_num'] = UnreadTalkCache::getInstance()->read($item['receiver_id'], $user_id); - $data['is_online'] = container()->get(SocketClientService::class)->isOnlineAll($item['receiver_id'], $runIdAll); - $data['remark_name'] = container()->get(UserFriendService::class)->getFriendRemark($user_id, $item['receiver_id']); + $data['is_online'] = di()->get(SocketClientService::class)->isOnlineAll($item['receiver_id'], $runIdAll); + $data['remark_name'] = di()->get(UserFriendService::class)->getFriendRemark($user_id, $item['receiver_id']); } else if (TalkModeConstant::GROUP_CHAT) { $data['name'] = strval($item['group_name']); $data['avatar'] = $item['group_avatar']; diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index 74cc864..a719934 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -81,7 +81,7 @@ class TalkService extends BaseService }); $rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->limit($limit)->get()->toArray(); - return container()->get(FormatMessageService::class)->handleChatRecords($rows); + return di()->get(FormatMessageService::class)->handleChatRecords($rows); } /** @@ -124,7 +124,7 @@ class TalkService extends BaseService $rowsSqlObj->whereIn('talk_records.id', explode(',', $forward->records_id)); $rows = $rowsSqlObj->get()->toArray(); - return container()->get(FormatMessageService::class)->handleChatRecords($rows); + return di()->get(FormatMessageService::class)->handleChatRecords($rows); } /** @@ -325,7 +325,7 @@ class TalkService extends BaseService $sqlObj = TalkRecords::whereIn('id', $records_ids); if ($talk_type == TalkModeConstant::PRIVATE_CHAT) { - if (!container()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true)) return []; + if (!di()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true)) return []; $sqlObj = $sqlObj->where(function ($query) use ($user_id, $receiver_id) { $query->where([ @@ -476,7 +476,7 @@ class TalkService extends BaseService } $rows = $rowsSqlObj->orderBy('talk_records.id', 'desc')->forPage($page, $page_size)->get()->toArray(); - $rows = container()->get(FormatMessageService::class)->handleChatRecords($rows); + $rows = di()->get(FormatMessageService::class)->handleChatRecords($rows); return $this->getPagingRows($rows, $count, $page, $page_size); } diff --git a/app/Service/UserService.php b/app/Service/UserService.php index 84f9c13..0c91ba5 100644 --- a/app/Service/UserService.php +++ b/app/Service/UserService.php @@ -125,11 +125,11 @@ class UserService extends BaseService // 判断查询信息是否是自己 if ($friend_id != $me_user_id) { - $is_friend = container()->get(UserFriendService::class)->isFriend($me_user_id, $friend_id, true); + $is_friend = di()->get(UserFriendService::class)->isFriend($me_user_id, $friend_id, true); $info['friend_status'] = $is_friend ? 2 : 1; if ($is_friend) { - $info['nickname_remark'] = container()->get(UserFriendService::class)->getFriendRemark($me_user_id, $friend_id); + $info['nickname_remark'] = di()->get(UserFriendService::class)->getFriendRemark($me_user_id, $friend_id); } else { $res = UsersFriendApply::where('user_id', $me_user_id) ->where('friend_id', $friend_id) diff --git a/app/Support/MailerTemplate.php b/app/Support/MailerTemplate.php index b125dce..7efe43a 100644 --- a/app/Support/MailerTemplate.php +++ b/app/Support/MailerTemplate.php @@ -21,7 +21,7 @@ class MailerTemplate */ private function view(string $engine, string $template, $params = []): string { - return container()->get($engine)->render($template, $params, config('view.config', [])); + return di()->get($engine)->render($template, $params, config('view.config', [])); } /** diff --git a/app/Support/SendEmailCode.php b/app/Support/SendEmailCode.php index ee57530..db7f413 100644 --- a/app/Support/SendEmailCode.php +++ b/app/Support/SendEmailCode.php @@ -59,7 +59,7 @@ class SendEmailCode // ...执行发送(后期使用队列) email()->send( $email, 'Lumen IM(绑定邮箱验证码)', - container()->get(MailerTemplate::class)->emailCode($sms_code) + di()->get(MailerTemplate::class)->emailCode($sms_code) ); return true; diff --git a/app/Support/UserRelation.php b/app/Support/UserRelation.php index b2e60ee..fab994a 100644 --- a/app/Support/UserRelation.php +++ b/app/Support/UserRelation.php @@ -19,7 +19,7 @@ class UserRelation public static function isFriendOrGroupMember(int $user_id, int $receiver_id, int $talk_type) { if ($talk_type == TalkModeConstant::PRIVATE_CHAT) { - return container()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true); + return di()->get(UserFriendService::class)->isFriend($user_id, $receiver_id, true); } else if ($talk_type == TalkModeConstant::GROUP_CHAT) { return Group::isMember($receiver_id, $user_id); } diff --git a/app/helper.php b/app/helper.php index 605dc6b..a36aa51 100644 --- a/app/helper.php +++ b/app/helper.php @@ -21,7 +21,7 @@ use Hyperf\Redis\Redis; * * @return \Psr\Container\ContainerInterface */ -function container() +function di() { return ApplicationContext::getContainer(); } @@ -33,7 +33,7 @@ function container() */ function redis() { - return container()->get(Redis::class); + return di()->get(Redis::class); } /** @@ -43,7 +43,7 @@ function redis() */ function server() { - return container()->get(ServerFactory::class)->getServer()->getServer(); + return di()->get(ServerFactory::class)->getServer()->getServer(); } /** @@ -53,7 +53,7 @@ function server() */ function frame() { - return container()->get(Frame::class); + return di()->get(Frame::class); } /** @@ -63,7 +63,7 @@ function frame() */ function websocket() { - return container()->get(WebSocketServer::class); + return di()->get(WebSocketServer::class); } /** @@ -73,7 +73,7 @@ function websocket() */ function cache() { - return container()->get(Psr\SimpleCache\CacheInterface::class); + return di()->get(Psr\SimpleCache\CacheInterface::class); } /** @@ -81,7 +81,7 @@ function cache() */ function event() { - return container()->get(\Psr\EventDispatcher\EventDispatcherInterface::class); + return di()->get(\Psr\EventDispatcher\EventDispatcherInterface::class); } /** @@ -91,7 +91,7 @@ function event() */ function stdout_log() { - return container()->get(StdoutLoggerInterface::class); + return di()->get(StdoutLoggerInterface::class); } /** @@ -102,7 +102,7 @@ function stdout_log() */ function logger(string $name = 'APP') { - return container()->get(LoggerFactory::class)->get($name); + return di()->get(LoggerFactory::class)->get($name); } /** @@ -112,7 +112,7 @@ function logger(string $name = 'APP') */ function request() { - return container()->get(ServerRequestInterface::class); + return di()->get(ServerRequestInterface::class); } /** @@ -122,13 +122,13 @@ function request() */ function response() { - return container()->get(ResponseInterface::class); + return di()->get(ResponseInterface::class); } function email() { - return container()->get(\App\Support\Mail::class); + return di()->get(\App\Support\Mail::class); } @@ -257,7 +257,7 @@ function parse_ids($ids) */ function push_amqp(\Hyperf\Amqp\Message\ProducerMessage $message, bool $confirm = false, int $timeout = 5) { - return container()->get(\Hyperf\Amqp\Producer::class)->produce($message, $confirm, $timeout); + return di()->get(\Hyperf\Amqp\Producer::class)->produce($message, $confirm, $timeout); } /**