[FEATURE] 代理类生成优化
tw2066 opened this issue · comments
现象
目前生成的代理类和源文件的代码行数不一致,当出现报错的时候(特别是线上), 很难通过行数来找到具体的报错
例子
原始类
<?php
namespace App\Service;
use Hyperf\Macroable\Macroable;
class Goods2
{
use Macroable;
public function t1()
{
return 'goods2-t1';
}
}
生成代理类
<?php
namespace App\Service;
use Hyperf\Macroable\Macroable;
class Goods2 extends GoodsInfoService
{
use \Hyperf\Di\Aop\ProxyTrait;
use \Hyperf\Di\Aop\PropertyHandlerTrait;
function __construct()
{
if (method_exists(parent::class, '__construct')) {
parent::__construct(...func_get_args());
}
$this->__handlePropertyHandler(__CLASS__);
}
use Macroable;
public function t1()
{
return 'goods2-t1';
}
}
建议
是否考虑保证生成的代理类尽可能保证原始代码行数保持一致
<?php
namespace App\Service;
use Hyperf\Macroable\Macroable;
class Goods2 extends GoodsInfoService
{ use \Hyperf\Di\Aop\ProxyTrait;use \Hyperf\Di\Aop\PropertyHandlerTrait;function __construct(){if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args());}$this->__handlePropertyHandler(__CLASS__);}
use Macroable;
public function t1()
{
return 'goods2-t1';
}
}
不现实,错误日志也暴露了代理类的路径+行数。如果说不方便直接操作生产环境的源文件。不如加个 sentry 来做错误追踪
…---原始邮件---
发件人: ***@***.***>
发送时间: 2024年5月9日(周四) 下午2:55
收件人: ***@***.***>;
抄送: ***@***.***>;
主题: [hyperf/hyperf] [FEATURE] 代理类生成优化 (Issue #6739)
现象
目前生成的代理类和源文件的代码行数不一致,当出现报错的时候(特别是线上), 很难通过行数来找到具体的报错
例子
原始类
<?php namespace App\Service; use Hyperf\Macroable\Macroable; class Goods2 { use Macroable; public function t1() { return 'goods2-t1'; } }
生成代理类
<?php namespace App\Service; use Hyperf\Macroable\Macroable; class Goods2 extends GoodsInfoService { use \Hyperf\Di\Aop\ProxyTrait; use \Hyperf\Di\Aop\PropertyHandlerTrait; function __construct() { if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args()); } $this->__handlePropertyHandler(__CLASS__); } use Macroable; public function t1() { return 'goods2-t1'; } }
建议
是否考虑保证生成的代理类尽可能保证原始代码行数保持一致
<?php namespace App\Service; use Hyperf\Macroable\Macroable; class Goods2 extends GoodsInfoService { use \Hyperf\Di\Aop\ProxyTrait;use \Hyperf\Di\Aop\PropertyHandlerTrait;function __construct(){if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args());}$this->__handlePropertyHandler(__CLASS__);} use Macroable; public function t1() { return 'goods2-t1'; } }
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
如果这个函数存在 Aspect 的话,那要怎么保证行号一致呢?/狗头
<?php
namespace App\Service;
use Hyperf\Macroable\Macroable;
class Goods2 extends GoodsInfoService
{ use \Hyperf\Di\Aop\ProxyTrait;use \Hyperf\Di\Aop\PropertyHandlerTrait;function __construct(){if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args());}$this->__handlePropertyHandler(__CLASS__);}
use Macroable;
public function t1()
{$__function__ = __FUNCTION__;$__method__ = __METHOD__;return self::__proxyCall(__CLASS__, __FUNCTION__, ['keys' => []], function () use($__function__, $__method__) {
return 'goods2-t1';
});}
}
Sentry +1 真香
为什么不能把/runtime/proxy/
直接在每次版本发布时候编译出来同步更新到仓库?排查时候也有源文件给你看。
而且你也可以使用其他方式获取异常信息。
这个优化没什么必要性。
<?php namespace App\Service; use Hyperf\Macroable\Macroable; class Goods2 extends GoodsInfoService { use \Hyperf\Di\Aop\ProxyTrait;use \Hyperf\Di\Aop\PropertyHandlerTrait;function __construct(){if (method_exists(parent::class, '__construct')) { parent::__construct(...func_get_args());}$this->__handlePropertyHandler(__CLASS__);} use Macroable; public function t1() {$__function__ = __FUNCTION__;$__method__ = __METHOD__;return self::__proxyCall(__CLASS__, __FUNCTION__, ['keys' => []], function () use($__function__, $__method__) { return 'goods2-t1'; });} }
我设想过你会引入 Sentry ,记录日志等各种操作,唯独没想到你会给出这个方案。
如果是为了实现而实现,那你确实厉害。