Wedge

Public area => The Pub => Plugins => Topic started by: Dragooon on January 19th, 2013, 11:15 PM

Title: Plugin dependency loading
Post by: Dragooon on January 19th, 2013, 11:15 PM
This is a pretty tricky topic, if a plugin B relies on a plugin A and Wedge loads plugin B before A, there's a good chance it'll crash and burn (especially in my case since I use class interfaces and all). Perhaps they should be loaded in the order they're enabled?
Title: Re: Plugin dependency loading
Post by: Arantor on January 19th, 2013, 11:18 PM
That's why they can set priorities :D
Title: Re: Plugin dependency loading
Post by: Dragooon on January 19th, 2013, 11:18 PM
Quote from Arantor on January 19th, 2013, 11:18 PM
That's why they can set priorities :D
Wait, what?
Title: Re: Plugin dependency loading
Post by: Arantor on January 19th, 2013, 11:21 PM
I implemented it like months ago. A given hooked function can declare its priority in the running order, so if it suspects it's going to be running after something else, the plugin-info.xml can give it a lower priority to run with.

In the <function> item, there's an attribute for priority, of 1-100 with 50 being the default.
Title: Re: Plugin dependency loading
Post by: Dragooon on January 19th, 2013, 11:39 PM
Okay...how do I solve this then, I have three plugins. A, B, C.

C requires both B and A to be included before throwing a parse eror. Both B and A hook into load_theme and call two individual hooks, both of which are hooked by C. Now if either calls the hook, it throws a parse error since the other is not loaded.
Title: Re: Plugin dependency loading
Post by: Arantor on January 19th, 2013, 11:49 PM
explain 'both hooked by C'?

But still sounds like C needs a lower priority than both A and B.
Title: Re: Plugin dependency loading
Post by: Dragooon on January 19th, 2013, 11:52 PM
Quote from Arantor on January 19th, 2013, 11:49 PM
explain 'both hooked by C'?

But still sounds like C needs a lower priority than both A and B.
"Both hooked by C" means that C calls both the hooks declared by A and B which they call during load_theme callback. C does have a lower priority than A and B, in this situation one will call before the other and cause the parse error.
Title: Re: Plugin dependency loading
Post by: Arantor on January 19th, 2013, 11:53 PM
So what's the problem then? Plugin C won't be *loaded* until the hooks are called from A and B.
Title: Re: Plugin dependency loading
Post by: Dragooon on January 19th, 2013, 11:58 PM
Quote from Arantor on January 19th, 2013, 11:53 PM
So what's the problem then? Plugin C won't be *loaded* until the hooks are called from A and B.
See it goes like this, plugin A declares a PHP interface interfaceA and B declares another interface interfaceB. Both A and B have callbacks for load_theme in which they initiate another hook call each. Now before this their plugin files are not included since they're not called. Let's assume A has a higher priority than B which has a higher priority than C (A > B > C).

C comes in, and adds callback for the hooks called by A and B. Now C's PHP files uses both interfaceA and interfaceB, A will call C's hook callback but this will be before B gets a chance to load it's PHP file. And it'll end in a parse error.
Title: Re: Plugin dependency loading
Post by: Arantor on January 20th, 2013, 12:05 AM
OK, so I see the problem.

Multi inheritance is inherently (pun not intended) is voodoo, seems to me the solution is for plugins to be able to declare an autoloader?
Title: Re: Plugin dependency loading
Post by: Dragooon on January 20th, 2013, 12:06 AM
Quote from Arantor on January 20th, 2013, 12:05 AM
OK, so I see the problem.

Multi inheritance is inherently (pun not intended) is voodoo, seems to me the solution is for plugins to be able to declare an autoloader?
I was thinking more alongs the line of including all the plugin files in some priority before actually calling the hooks?
Title: Re: Plugin dependency loading
Post by: Arantor on January 20th, 2013, 12:10 AM
Given how many files that could require per page? No.

The whole point of hooks having loading function is that they load what they need when they need it - forcing it to load everything up front adds a *massive* weight.
Posted: January 20th, 2013, 12:08 AM

I should also add that I personally don't write a lot of interfaces, so this would simply have never occurred to me as a potential issue.
Title: Re: Plugin dependency loading
Post by: Dragooon on January 20th, 2013, 12:12 AM
Quote from Arantor on January 20th, 2013, 12:10 AM
Given how many files that could require per page? No.

The whole point of hooks having loading function is that they load what they need when they need it - forcing it to load everything up front adds a *massive* weight.
Posted: January 20th, 2013, 12:08 AM

I should also add that I personally don't write a lot of interfaces, so this would simply have never occurred to me as a potential issue.
Fair enough, autoloader can work. Or I can simply split my files into two, dunno why that didn't occur to me earlier.