1. Go to this page and download the library: Download hyperf/aop-integration library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Hyperf\AopIntegration\ClassLoader;
if ($timezone = config('app.default_timezone')) {
date_default_timezone_set($timezone);
}
// 初始化
ClassLoader::init();
namespace app\service;
class UserService
{
public function first(): array
{
return ['id' => 1];
}
}
namespace app\aspect;
use app\service\UserService;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
class DebugAspect extends AbstractAspect
{
public $classes = [
UserService::class . '::first',
];
public function process(ProceedingJoinPoint $proceedingJoinPoint)
{
var_dump(11);
return $proceedingJoinPoint->process();
}
}
namespace app\controller;
use app\service\UserService;
use support\Request;
class Index
{
public function json(Request $request)
{
return json(['code' => 0, 'msg' => 'ok', 'data' => (new UserService())->first()]);
}
}