feat : Decorator Aop
This commit is contained in:
31
app/Service/Test/Decorator/Aop/UserService.php
Normal file
31
app/Service/Test/Decorator/Aop/UserService.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Decorator\Aop;
|
||||
|
||||
use App\Interface\Test\Decorator\UserServiceInterface;
|
||||
|
||||
class UserService implements UserServiceInterface
|
||||
{
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return array
|
||||
*/
|
||||
public function getUserInfo(int $userId): array
|
||||
{
|
||||
// 模拟数据库查询
|
||||
return [
|
||||
'id' => $userId,
|
||||
'name' => 'User ' . $userId,
|
||||
'email' => 'user' . $userId . '@ctexthuang.com'
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,25 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Decorator;
|
||||
|
||||
use App\Service\Test\Decorator\Aop\UserService;
|
||||
use App\Service\Test\TestBaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class AopService extends TestBaseService
|
||||
{
|
||||
public function handle()
|
||||
/**
|
||||
* @var UserService
|
||||
*/
|
||||
#[Inject]
|
||||
protected UserService $userService;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
return $this->return->success();
|
||||
$userInfo = $this->userService->getUserInfo($this->request->input('user_id',1));
|
||||
|
||||
return $this->return->success('获取用户信息成功', $userInfo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user