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

All args not being passed to event handler function #14

Open
evtaylor opened this issue Mar 26, 2015 · 2 comments
Open

All args not being passed to event handler function #14

evtaylor opened this issue Mar 26, 2015 · 2 comments

Comments

@evtaylor
Copy link

Bug only appears to happen when adding listener to event that has more than one arg. Example 'baun.beforePageRender'.

Baun emits event like this:

$this->events->emit('baun.beforePostRender', $template, $data);

But Baun events provider emit function only accepts 2 arguments:

public function emit($event, $args = [])
{
    $this->emitter->emit($event, $args);
}

Therefore $template gets passed through and $data does not.

This could be fixed by emitting events with multiple args in an array:

$this->events->emit('baun.beforePageRender', [$template, $data]);
@evtaylor
Copy link
Author

Oh and as a second thought when Baun is emitting the 'baun.beforePageRender' event the it should pass the $data variable by reference so the event handling function is actually able to modify page data that gets rendered by the theme otherwise it only gets a copy of it.

So a fix could look something like this instead:

$this->events->emit('baun.beforePageRender', [$template, &$data]);

@maccath
Copy link
Contributor

maccath commented Apr 18, 2015

Just created a pull request #15 which fixes the issues mentioned here. It also fixes the issue with data variable being passed by reference; which is basically just changing the $data from an array to an object and back again before using, as only objects are passed by reference when using an arbitrary number of arguments as with func_get_args().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants