Plugin dependency loading

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Plugin dependency loading
« 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?
The way it's meant to be

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin dependency loading
« Reply #3, 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.

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Plugin dependency loading
« Reply #4, 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.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin dependency loading
« Reply #5, 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.

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Plugin dependency loading
« Reply #6, 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.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin dependency loading
« Reply #7, 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.

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Plugin dependency loading
« Reply #8, 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.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin dependency loading
« Reply #9, 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?

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Plugin dependency loading
« Reply #10, 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?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Plugin dependency loading
« Reply #11, 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.

Dragooon

  • I can code! Really!
  • polygon.com has to be one of the best sites I've seen recently.
  • Posts: 1,841
Re: Plugin dependency loading
« Reply #12, 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.