How to know phpBB version in getSubscribedEvents?

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

How to know phpBB version in getSubscribedEvents?

Post by pierredu »

Hello,

In an extension, I have two functions hooking different events depending on phpBB version.
But the injected $config is not yet accessible when this function gets executed (still null).

Several options :
1. Different versions of the extension
2. Hooking both events and checking at execute time if I run under the good version.
3. What else?

Thanks in advance for your comments.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: How to know phpBB version in getSubscribedEvents?

Post by GanstaZ »

Why you need it? 3.1.x is EOL (history) & 3.3 is not out yet.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to know phpBB version in getSubscribedEvents?

Post by pierredu »

I just want to keep my extension running under 3.1.x.
The dirty work is done.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to know phpBB version in getSubscribedEvents?

Post by 3Di »

Code: Select all

if ($this->phpbb_container->has('core.the_event_for_31.blah'))
{
	// your magic
}
should do, not tested.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to know phpBB version in getSubscribedEvents?

Post by pierredu »

Marco,

Thanks a lot.
I'll test and report my findings.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to know phpBB version in getSubscribedEvents?

Post by 3Di »

Returns TRUE if... true. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to know phpBB version in getSubscribedEvents?

Post by pierredu »

Well, it doesn't work.
Here is the code snippet :

Code: Select all

global $phpbb_container;
if ($phpbb_container->has('core.text_formatter_s9e_render_after'))
{
	var_dump ("True. Version 3.2.");
	// return array...
}
else
{
	var_dump ("False. Version 3.1.");
	// return array...
}
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: How to know phpBB version in getSubscribedEvents?

Post by 3Di »

Pierre, take me to the code and I will get a look.
There are different ways to do something like you want it to do depending on the use cases, an example is my extension (validated)
https://github.com/3D-I/Default-Avatar-Extended

I need to lurk at your code to try and help you more, if I can. :)
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: How to know phpBB version in getSubscribedEvents?

Post by kasimi »

You cannot check if an event exists. phpBB would have to parse all files in your board to find out. You can use the dispatcher service to check if there is a listener registered for a specific event, but there's no generic way to tell if it ever gets triggered, until it does.

Which two events are you hooking into? The very first in phpBB core is core.common. By the time it is triggered, the config service is set up and ready for use.

Be that as it may, you should prefer using the constant PHPBB_VERSION instead of $config['version'].
User avatar
pierredu
Registered User
Posts: 1256
Joined: Thu Nov 01, 2012 8:04 am
Location: Paris (France)

Re: How to know phpBB version in getSubscribedEvents?

Post by pierredu »

https://github.com/pierrdu/lmdi_gloss

I commented out the trial code in getSubscribedEvents and the version checking is done in both functions (for 3.1.x and 3.2.x).
Post Reply

Return to “Extension Writers Discussion”