Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加新事件,trigger时报错 #377

Closed
alukaa opened this issue Sep 5, 2018 · 6 comments · Fixed by swoft-cloud/swoft-component#196
Closed

添加新事件,trigger时报错 #377

alukaa opened this issue Sep 5, 2018 · 6 comments · Fixed by swoft-cloud/swoft-component#196
Assignees
Labels

Comments

@alukaa
Copy link

alukaa commented Sep 5, 2018

Q A
Bug report? yes
Feature request? no
Swoft version 1.0.0
Swoole version 4.0.1
PHP version 7.2.8
Runtime environment Docker

Details

添加事件定义如下:

 $show = new TestShow();
 App::getBean('eventManager')->attach('demo:showCase',[$show, 'test2'], 1);
 App::trigger('demo:showCase', null, [1,2,3,4]);

class TestShow
{ 
  public function test2(...$params)
    {
        var_dump($params);
        var_dump('test2');
        //App::error(__FUNCTION__);
    }
}
{"msg":"Argument 2 passed to Swoft\\Helper\\PhpHelper::call() must be of the type array, object given, called in \/var\/www\/swoft-research\/vendor\/swoft\/framework\/src\/Event\/LazyListener.php on line 30","file":"\/var\/www\/swoft-research\/vendor\/swoft\/framework\/src\/Helper\/PhpHelper.php","line":40,"code":0}

Provide minimal script to reproduce the issue

原因分析:

App::getBean('eventManager')->attach('demo:showCase',[$show, 'test2'], 1);

会调用LazyListener
image,
但是LazyListener在调用handle方法时传递的参数是EventInterface $event,而\Swoft\Helper\PhpHelper::call接受的是array
这里应该接收event$->getParams()?

// paste code
@alukaa
Copy link
Author

alukaa commented Sep 5, 2018

@inhere 效率

@inhere
Copy link
Member

inhere commented Sep 5, 2018

@alukaa 你参照PR修改试试看呢。

trigger时始终会传递 event 对象给用户处理的。 params 需自己从event对象中拿取

@alukaa
Copy link
Author

alukaa commented Sep 5, 2018

image
image
按照PR进行修改得到了以下结果,可以得到event object,
目测这样没有问题了

@inhere
Copy link
Member

inhere commented Sep 5, 2018

😄 行,感谢反馈 👍

@alukaa
Copy link
Author

alukaa commented Sep 5, 2018

@inhere 效率真高,给个star,哈哈

@alukaa alukaa closed this as completed Sep 5, 2018
huangzhhui pushed a commit to swoft-cloud/swoft-component that referenced this issue Sep 5, 2018
huangzhhui pushed a commit to swoft-cloud/swoft-framework that referenced this issue Sep 5, 2018
@huangzhhui
Copy link
Contributor

swoft-bot pushed a commit to swoft-cloud/swoft-framework that referenced this issue Nov 21, 2018
stelin pushed a commit to swoft-cloud/swoft-framework that referenced this issue May 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants