Re: What's the best way to make a dynamic plugin architecture?

From: Date: Mon, 27 Aug 2012 13:52:57 +0000
Subject: Re: What's the best way to make a dynamic plugin architecture?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-318876@lists.php.net to get a copy of this message
On Mon, Aug 27, 2012 at 3:46 PM, Stuart Dallas <stuart@3ft9.com> wrote: > On 27 Aug 2012, at 14:29, Mark <markg85@gmail.com> wrote: > >> On Mon, Aug 27, 2012 at 12:41 PM, Stuart Dallas <stuart@3ft9.com> wrote: >>> On 26 Aug 2012, at 19:42, Mark <markg85@gmail.com> wrote: >>> >>>> 2. Let the plugin itself (so in this case PluginOne.php) open itself >>>> and register it to the PluginLoader. >>>> >>>> With the first option i have to do eval which i try to avoid if possible. >>>> With the second solution the PluginLoader probably has to be a singlethon. >>> >>> Why does it need to be a singleton? >> >> Well, i would then do something like this from within the included >> plugin file after the class: >> PluginLoader::getInstance()->registerPlugin(new PluginOne()); >> >> Or something alike. > > I'm not sure I see what PluginLoader is doing? It makes more sense to me if you register > like so: > > PluginLoader::getInstance()->registerPlugin('PluginOne'); > > Then you get an instance of the plugin: > > $plugin = PluginLoader::getInstance()->factory('PluginOne'); > > Tho, even then I don't see what the PluginLoader is adding to the party. Well, i'm making the classes up as i type. I don't actually have a PluginLoader yet. Or rather, i'm just beginning to make it right now. What it's doing is very simple. Read through the directory of the plugins and load every single plugin it finds in memory. Then every plugin registers the mime types it can handle. That information is stored in the PluginLoader upon which some other place can call: PluginLoader::pluginForMime("text/html"). Though i still have to take a good look at that. But you're right, i can use the factory pattern here. > >> Thank you for your advice, really appreciated. > > > No probs. > > -Stuart > > -- > Stuart Dallas > 3ft9 Ltd > http://3ft9.com/

« previous php.general (#318876) next »