-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
241 changed files
with
5,522 additions
and
6,059 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
$header = <<<'EOF' | ||
This file is part of MineAdmin. | ||
@link https://www.mineadmin.com | ||
@document https://doc.mineadmin.com | ||
@contact [email protected] | ||
@license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
EOF; | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@PSR2' => true, | ||
'@Symfony' => true, | ||
'@DoctrineAnnotation' => true, | ||
'@PhpCsFixer' => true, | ||
'header_comment' => [ | ||
'comment_type' => 'PHPDoc', | ||
'header' => $header, | ||
'separate' => 'none', | ||
'location' => 'after_declare_strict', | ||
], | ||
'array_syntax' => [ | ||
'syntax' => 'short' | ||
], | ||
'list_syntax' => [ | ||
'syntax' => 'short' | ||
], | ||
'concat_space' => [ | ||
'spacing' => 'one' | ||
], | ||
'blank_line_before_statement' => [ | ||
'statements' => [ | ||
'declare', | ||
], | ||
], | ||
'general_phpdoc_annotation_remove' => [ | ||
'annotations' => [ | ||
'author' | ||
], | ||
], | ||
'ordered_imports' => [ | ||
'imports_order' => [ | ||
'class', 'function', 'const', | ||
], | ||
'sort_algorithm' => 'alpha', | ||
], | ||
'single_line_comment_style' => [ | ||
'comment_types' => [ | ||
], | ||
], | ||
'yoda_style' => [ | ||
'always_move_variable' => false, | ||
'equal' => false, | ||
'identical' => false, | ||
], | ||
'phpdoc_align' => [ | ||
'align' => 'left', | ||
], | ||
'multiline_whitespace_before_semicolons' => [ | ||
'strategy' => 'no_multi_line', | ||
], | ||
'constant_case' => [ | ||
'case' => 'lower', | ||
], | ||
'class_attributes_separation' => true, | ||
'combine_consecutive_unsets' => true, | ||
'declare_strict_types' => true, | ||
'linebreak_after_opening_tag' => true, | ||
'lowercase_static_reference' => true, | ||
'no_useless_else' => true, | ||
'no_unused_imports' => true, | ||
'not_operator_with_successor_space' => true, | ||
'not_operator_with_space' => false, | ||
'ordered_class_elements' => true, | ||
'php_unit_strict' => false, | ||
'phpdoc_separation' => false, | ||
'single_quote' => true, | ||
'standardize_not_equals' => true, | ||
'multiline_comment_opening_closing' => true, | ||
]) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->exclude('vendor') | ||
->exclude('bin') | ||
->in(__DIR__) | ||
) | ||
->setUsingCache(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,57 +10,77 @@ | |
*/ | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Api; | ||
|
||
use Api\Middleware\VerifyInterfaceMiddleware; | ||
use App\System\Service\SystemAppService; | ||
use Hyperf\Di\Annotation\AnnotationCollector; | ||
use Hyperf\Di\Annotation\MultipleAnnotation; | ||
use Hyperf\Di\ReflectionManager; | ||
use Hyperf\HttpServer\Annotation\Controller; | ||
use Hyperf\HttpServer\Annotation\Middlewares; | ||
use Hyperf\HttpServer\Annotation\PostMapping; | ||
use Hyperf\HttpServer\Annotation\RequestMapping; | ||
use Hyperf\Validation\Request\FormRequest; | ||
use Hyperf\Validation\ValidationException; | ||
use Mine\Exception\NoPermissionException; | ||
use Mine\Exception\NormalStatusException; | ||
use Mine\Exception\TokenException; | ||
use Mine\Helper\MineCode; | ||
use Mine\MineApi; | ||
use Hyperf\HttpServer\Annotation\Controller; | ||
use Hyperf\HttpServer\Annotation\RequestMapping; | ||
use Hyperf\Di\Annotation\AnnotationCollector; | ||
use Hyperf\Di\Annotation\MultipleAnnotation; | ||
use Hyperf\Di\ReflectionManager; | ||
use Hyperf\Validation\Request\FormRequest; | ||
use Hyperf\Validation\ValidationException; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Api\Middleware\VerifyInterfaceMiddleware; | ||
|
||
/** | ||
* Class ApiController | ||
* @package Api | ||
* Class ApiController. | ||
*/ | ||
#[Controller(prefix: "api")] | ||
#[Controller(prefix: 'api')] | ||
class ApiController extends MineApi | ||
{ | ||
public const SIGN_VERSION = '1.0'; | ||
|
||
/** | ||
* 获取accessToken | ||
* @return ResponseInterface | ||
* 初始化. | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
protected function __init() | ||
{ | ||
if (empty($this->request->input('apiData'))) { | ||
throw new NormalStatusException(t('mineadmin.access_denied'), MineCode::NORMAL_STATUS); | ||
} | ||
|
||
return $this->request->input('apiData'); | ||
} | ||
|
||
/** | ||
* 获取accessToken. | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
* @throws \Psr\SimpleCache\InvalidArgumentException | ||
*/ | ||
#[PostMapping("v1/getAccessToken")] | ||
#[PostMapping('v1/getAccessToken')] | ||
public function getAccessToken(): ResponseInterface | ||
{ | ||
$service = container()->get(SystemAppService::class); | ||
return $this->success($service->getAccessToken($this->request->all())); | ||
} | ||
|
||
/** | ||
* v1 版本 | ||
* @return ResponseInterface | ||
* v1 版本. | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
#[RequestMapping("v1/{method}")] | ||
#[Middlewares([ VerifyInterfaceMiddleware::class ])] | ||
#[RequestMapping('v1/{method}')] | ||
#[Middlewares([VerifyInterfaceMiddleware::class])] | ||
public function v1(): ResponseInterface | ||
{ | ||
$apiData = $this->__init(); | ||
|
@@ -80,7 +100,7 @@ public function v1(): ResponseInterface | |
$args[] = $formRequest; | ||
if ($formRequest instanceof FormRequest) { | ||
$this->handleSceneAnnotation($formRequest, $apiData['class_name'], $apiData['method_name'], $parameter->getName()); | ||
// 验证, 这里逻辑和 验证中间件一样 直接抛异常 | ||
// 验证, 这里逻辑和 验证中间件一样 直接抛异常 | ||
$formRequest->validateResolved(); | ||
} | ||
} | ||
|
@@ -97,30 +117,16 @@ public function v1(): ResponseInterface | |
throw new NormalStatusException(t('mineadmin.interface_exception') . $error, MineCode::INTERFACE_EXCEPTION); | ||
} | ||
if ($e instanceof NoPermissionException) { | ||
throw new NormalstatusException( t( key: 'mineadmin.api_auth_fail') . $e->getMessage(), code: MineCode::NO_PERMISSION); | ||
throw new NormalstatusException(t(key: 'mineadmin.api_auth_fail') . $e->getMessage(), code: MineCode::NO_PERMISSION); | ||
} | ||
if ($e instanceof TokenException) { | ||
throw new NormalstatusException( t( key: 'mineadmin.api_auth_exception') . $e->getMessage(), code: MineCode::TOKEN_EXPIRED); | ||
throw new NormalstatusException(t(key: 'mineadmin.api_auth_exception') . $e->getMessage(), code: MineCode::TOKEN_EXPIRED); | ||
} | ||
|
||
throw new NormalstatusException( t( key: 'mineadmin.interface_exception') . $e->getMessage(), code: MineCode::INTERFACE_EXCEPTION); | ||
throw new NormalstatusException(t(key: 'mineadmin.interface_exception') . $e->getMessage(), code: MineCode::INTERFACE_EXCEPTION); | ||
} | ||
} | ||
|
||
/** | ||
* 初始化 | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
protected function __init() | ||
{ | ||
if (empty($this->request->input('apiData'))) { | ||
throw new NormalStatusException(t('mineadmin.access_denied'), MineCode::NORMAL_STATUS); | ||
} | ||
|
||
return $this->request->input('apiData'); | ||
} | ||
|
||
protected function handleSceneAnnotation(FormRequest $request, string $class, string $method, string $argument): void | ||
{ | ||
/** @var null|MultipleAnnotation $scene */ | ||
|
@@ -142,4 +148,4 @@ protected function handleSceneAnnotation(FormRequest $request, string $class, st | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,45 +10,46 @@ | |
*/ | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace Api; | ||
|
||
use App\System\Service\SystemApiService; | ||
use App\System\Service\SystemAppService; | ||
use Hyperf\Di\Annotation\Inject; | ||
use Hyperf\HttpServer\Annotation\Controller; | ||
use Hyperf\HttpServer\Annotation\GetMapping; | ||
use Hyperf\HttpServer\Annotation\PostMapping; | ||
use Mine\Annotation\Api\MApiCollector; | ||
use Mine\Helper\MineCode; | ||
use Mine\MineApi; | ||
use Hyperf\HttpServer\Annotation\Controller; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Mine\Annotation\Api\MApiCollector; | ||
|
||
/** | ||
* Class ApiDocController | ||
* @package Api | ||
* Class ApiDocController. | ||
*/ | ||
#[Controller(prefix: "apiDoc")] | ||
#[Controller(prefix: 'apiDoc')] | ||
class ApiDocController extends MineApi | ||
{ | ||
/** | ||
* @var SystemAppService | ||
*/ | ||
#[Inject] | ||
protected SystemAppService $systemAppService; | ||
|
||
/** | ||
* @var SystemApiService | ||
*/ | ||
#[Inject] | ||
protected SystemApiService $systemApiService; | ||
|
||
/** | ||
* 登录文档 | ||
* @return ResponseInterface | ||
* 登录文档. | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
#[PostMapping("login")] | ||
#[PostMapping('login')] | ||
public function login(): ResponseInterface | ||
{ | ||
$app_id = $this->request->input('app_id', ''); | ||
|
@@ -66,13 +67,11 @@ public function login(): ResponseInterface | |
} | ||
|
||
/** | ||
* 通过app id获取接口数据 | ||
* @param string $id | ||
* @return ResponseInterface | ||
* 通过app id获取接口数据. | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
#[GetMapping("getAppAndInterfaceList/{id}")] | ||
#[GetMapping('getAppAndInterfaceList/{id}')] | ||
public function getAppAndInterfaceList(string $id): ResponseInterface | ||
{ | ||
$appAndInterfaceList = $this->systemAppService->getAppAndInterfaceList($id); | ||
|
@@ -87,12 +86,10 @@ public function getAppAndInterfaceList(string $id): ResponseInterface | |
} | ||
|
||
/** | ||
* @param string $id | ||
* @return ResponseInterface | ||
* @throws \Psr\Container\ContainerExceptionInterface | ||
* @throws \Psr\Container\NotFoundExceptionInterface | ||
*/ | ||
#[GetMapping("getColumnList/{id}")] | ||
#[GetMapping('getColumnList/{id}')] | ||
public function getColumnList(string $id): ResponseInterface | ||
{ | ||
// 如果api注解收集器里有,直接返回信息 | ||
|
@@ -102,5 +99,4 @@ public function getColumnList(string $id): ResponseInterface | |
|
||
return $this->success($this->systemApiService->getColumnListByApiId($id)); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.