AOP的Hyperf组件可以生成 proxy代理类,但process方法未执行

9527

参考文档:https://www.workerman.net/doc/webman/aop.html

Workerman version:4.0.25
PHP version:7.4.25
Webman 1.0

composer.json

"autoload": {
    "psr-4": {
        "app\\": "app/"
    },
    "files": [
      "./support/helpers.php"
    ]
  },

router.php:

Route::any('/abcdb', [app\common\controller\Login::class, 'logDb']);

config.php

return [
    'annotations' => [
        'scan' => [
            'paths' => [
                BASE_PATH . '/app',
            ],
            'ignore_annotations' => [
                'mixin',
            ],
            'class_map' => [
            ],
        ],
    ],
    'aspects' => [
        // 这里写入对应的 Aspect
        app\common\aspect\DebugAspect::class,
    ]
];

DebugAspect.php

namespace app\common\aspect;

class DebugAspect extends \Hyperf\Di\Aop\AbstractAspect
{
    public $classes = [
        \app\common\controller\Login::class . '::logDb',
    ];

    public function process(\Hyperf\Di\Aop\ProceedingJoinPoint $proceedingJoinPoint)
    {
        var_dump(123);
        echo 123;
        return $proceedingJoinPoint->process();
    }
}

Login.php

    public function logDb(): void
    {
        $log = new Log();
        $log->data = microtime(true);
        var_dump(microtime(true));
        $log->save();
    }

start.php,有配置初始化 ,启用服务后,runtime中的代理类有生成;

访问:http://127.0.0.1:8787/abcdb
预期:控制台要输出:123
结果:不符合预期,原因待查,请教大家;

2313 1 0
1个回答

walkor 打赏

AOP这个组件是另外一个开源作者提交到文档的,我并不熟悉它。之前有人测试过,并没有发现问题。

  • 暂无评论
年代过于久远,无法发表回答
×
🔝