Multiple Extensions Using Same Event

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
david63
Registered User
Posts: 18582
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Multiple Extensions Using Same Event

Post by david63 »

I don't know if this is a bug in the way phpBB handles events, intended behaviour, a change in the way Symfony works or just misuse/misunderstanding - if it is the last one then many extension developers are also guilty.

I know that, in theory at least, any number of extensions can use the same core event and I am fully aware that extension developers can add a priority to their running of an event. I am also aware that there is no defined order that extensions run but that they do appear to run alphabetically.

I have a situation where several of my extensions use the same event - in this case core.login_box_redirect, although I doubt that the actual event is relevant. What I have found is that when one extension with a priority of, say 90, runs it returns control back to the originating script and not to the extension with the next priority value, say 80.

The one thing that perhaps I should add is that these events are doing some actual processing rather than modifying the core data but I have never seen anywhere anything that says that an event needs to have some form of return at the end of it.

Another observation is that alphabetically the extension with the lower priority is higher alphabetically - i.e. extension G is running before extension A

Any Symfony experts around that can shed some light on this?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
rxu
Extensions Development Team
Posts: 3433
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Multiple Extensions Using Same Event

Post by rxu »

I'm not an expert, but I was absolutely sure vars having got extracted after every listener call before calling the next listener. But looking at the phpBB and Symfony source code now, I feel like all listeners for every event run first with the same data and only then all vars got extracted to the core.
So you get variable values the last event listener returns.

EDIT: currently it works like the following.
phpBB calls trigger_event() method, which calls phpBB's dispatch() method, which calls parent (Symfony) dispatch() method, which calls Symfony doDispatch() method, which calls all event listeners in a loop, then trigger_event() returns event data to extract() function which extracts vars to phpBB core.
In this logic, if you have var1 and var2 passed to event and 2 event listeners, where listener#1 runs 1st and changes var1, listener#2 runs 2nd and changes var2, at the end you will have var1 unchanged (because listener#2 got its original value and returned it unchanged) and var2 changed by listener2.

If this is correct, phpBB event dispatcher has to be fixed.
rxu
Extensions Development Team
Posts: 3433
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Multiple Extensions Using Same Event

Post by rxu »

Tested locally and it seems to be working correctly,
listener#2 gets the variable value changed by previous listener. So kinda false alarm :P
User avatar
david63
Registered User
Posts: 18582
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Multiple Extensions Using Same Event

Post by david63 »

That's not the same issue.

What I am talking about is where an extension uses an event to do some external processing and does not return any vars back to the core.

Essentially run the event, grab the vars at that point and do some processing, then move on to the next extension.

It seems to me that in this type of situation there should be some mechanism to return control back to the dispatcher (or whatever) so that the next extension can run.

It may also be a case of not using events in the way that they are intended - but many of us do, rightly or wrongly.
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
rxu
Extensions Development Team
Posts: 3433
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Multiple Extensions Using Same Event

Post by rxu »

Oh. Is there some example extension code to look into this?
Post Reply

Return to “Extension Writers Discussion”