目录结构调整

main
gzydong 2021-08-31 22:33:41 +08:00
parent d55098f815
commit 68d65e6933
17 changed files with 51 additions and 40 deletions

View File

@ -17,7 +17,7 @@ use Hyperf\HttpServer\Annotation\Middleware;
use App\Middleware\JWTAuthMiddleware;
use App\Model\User;
use App\Support\SendEmailCode;
use App\Helper\HashHelper;
use App\Helpers\HashHelper;
use App\Service\UserService;
use App\Service\SmsCodeService;
use Psr\Http\Message\ResponseInterface;

View File

@ -6,7 +6,7 @@ namespace App\Exception\Handler;
use App\Cache\Repository\LockRedis;
use App\Constants\ResponseCode;
use App\Support\MailerTemplate;
use App\Templates\MailerTemplate;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Helper;
namespace App\Helpers;
class ArrayHelper
{

View File

@ -9,7 +9,7 @@ declare(strict_types=1);
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;
namespace App\Helpers;
/**
* Hash 密码加密辅助类

View File

@ -8,7 +8,7 @@
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;
namespace App\Helpers;
use Hashids\Hashids;

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace App\Helper;
namespace App\Helpers;
/**
* 正则验证助手

View File

@ -9,7 +9,7 @@ declare(strict_types=1);
* @link https://github.com/gzydong/hyperf-chat
*/
namespace App\Helper;
namespace App\Helpers;
/**
* 字符串助手类

View File

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Repository;
use App\Helper\HashHelper;
use App\Helpers\HashHelper;
use App\Model\Talk\TalkRecords;
use App\Model\User;
use Hyperf\Utils\Str;

View File

@ -2,7 +2,7 @@
namespace App\Service;
use App\Helper\HashHelper;
use App\Helpers\HashHelper;
use App\Model\Robot;
use App\Model\User;
use Hyperf\DbConnection\Db;

View File

@ -2,7 +2,7 @@
namespace App\Service;
use App\Helper\HashHelper;
use App\Helpers\HashHelper;
use App\Model\User;
use App\Model\Article\ArticleClass;
use App\Model\UsersFriend;

View File

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace App\Support;
@ -21,7 +22,7 @@ class Response
* @param $data
* @return PsrResponseInterface
*/
public function json($data)
public function json($data): PsrResponseInterface
{
return $this->response->json($data);
}
@ -33,7 +34,7 @@ class Response
* @param string $message 响应提示
* @return PsrResponseInterface
*/
public function success(array $data = [], $message = 'success')
public function success(array $data = [], $message = 'success'): PsrResponseInterface
{
$code = ResponseCode::SUCCESS;
return $this->response->json(compact('code', 'message', 'data'));
@ -47,7 +48,7 @@ class Response
* @param int $code 错误码
* @return PsrResponseInterface
*/
public function fail($message = 'fail', $data = [], $code = ResponseCode::FAIL)
public function fail($message = 'fail', $data = [], $code = ResponseCode::FAIL): PsrResponseInterface
{
return $this->response->json(compact('code', 'message', 'data'));
}
@ -59,7 +60,7 @@ class Response
* @param int $code 错误码
* @return PsrResponseInterface
*/
public function error($message = '', $code = ResponseCode::SERVER_ERROR)
public function error($message = '', $code = ResponseCode::SERVER_ERROR): PsrResponseInterface
{
return $this->response->withStatus(500)->json([
'code' => $code,

View File

@ -2,6 +2,8 @@
namespace App\Support;
use App\Templates\MailerTemplate;
class SendEmailCode
{
const FORGET_PASSWORD = 'forget_password';
@ -16,7 +18,7 @@ class SendEmailCode
* @param string $mobile
* @return string
*/
private function getKey(string $type, string $mobile)
private function getKey(string $type, string $mobile): string
{
return "email_code:{$type}:{$mobile}";
}
@ -29,7 +31,7 @@ class SendEmailCode
* @param string $code 验证码
* @return bool
*/
public function check(string $type, string $email, string $code)
public function check(string $type, string $email, string $code): bool
{
$sms_code = redis()->get($this->getKey($type, $email));
if (!$sms_code) {
@ -84,7 +86,7 @@ class SendEmailCode
* @param float|int $exp 过期时间
* @return bool
*/
public function setCode(string $key, string $sms_code, $exp = 60 * 15)
public function setCode(string $key, string $sms_code, $exp = 60 * 15): bool
{
return redis()->setex($key, $exp, $sms_code);
}
@ -96,7 +98,7 @@ class SendEmailCode
* @param string $email 邮箱地址
* @return int
*/
public function delCode(string $type, string $email)
public function delCode(string $type, string $email): int
{
return redis()->del($this->getKey($type, $email));
}

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace App\Templates;
abstract class BaseTemplate
{
/**
* 获取模板信息
*
* @param string $engine 模板引擎
* @param string $template 模板名称
* @param array $params 模板参数
* @return string
*/
protected function view(string $engine, string $template, $params = []): string
{
return di()->get($engine)->render($template, $params, config('view.config', []));
}
}

View File

@ -1,29 +1,17 @@
<?php
declare(strict_types=1);
namespace App\Support;
namespace App\Templates;
use Throwable;
/**
* 邮件视图模板
* 邮件视图模板
*
* @package App\Support
* @package App\Templates
*/
class MailerTemplate
class MailerTemplate extends BaseTemplate
{
/**
* 获取模板信息
*
* @param string $engine 模板引擎
* @param string $template 模板名称
* @param array $params 模板参数
* @return string
*/
private function view(string $engine, string $template, $params = []): string
{
return di()->get($engine)->render($template, $params, config('view.config', []));
}
/**
* 验证码通知 - 邮件模板
*
@ -31,7 +19,7 @@ class MailerTemplate
* @param array $params 模板参数
* @return string
*/
public function emailCode(string $sms_code, array $params = [])
public function emailCode(string $sms_code, array $params = []): string
{
return $this->view(config('view.engine'), 'emails.verify-code', [
'service_name' => $params['service_name'] ?? "邮箱绑定",
@ -46,7 +34,7 @@ class MailerTemplate
* @param Throwable $throwable
* @return string
*/
public function errorNotice(Throwable $throwable)
public function errorNotice(Throwable $throwable): string
{
return $this->view(config('view.engine'), 'emails.error-notice', [
'throwable' => $throwable->getTraceAsString(),

View File

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace App\Traits;
use App\Helper\ArrayHelper;
use App\Helpers\ArrayHelper;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Hyperf\DbConnection\Db;

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace HyperfTest\Cases\Helper;
use App\Helper\ArrayHelper;
use App\Helpers\ArrayHelper;
use HyperfTest\HttpTestCase;
class ArrayHelperTest extends HttpTestCase

View File

@ -3,7 +3,7 @@ declare(strict_types=1);
namespace HyperfTest\Cases\Helper;
use App\Helper\RegularHelper;
use App\Helpers\RegularHelper;
use HyperfTest\HttpTestCase;
class RegularHelperTest extends HttpTestCase