Jump to content

Addon Capable Applications


mattnoble

Recommended Posts

I was just curious if anyone knew the general theory behind how to create PHP applications with addon support. How would you implement addons that people create and how exactly are they created. Are the addons just classes and functions that are added into the code somehow. I don't even know if I'm wording this right haha. What comes to mind mainly is WordPress, and it's huge addon repository and I was just curious if anyone knew how this was done, not specifically for WP, but in general. Thanks a lot!  :)
Link to comment
Share on other sites

Implement the Observer Pattern into the 'core' of your application (usually invoked by the front controller and stored in a registry.) Use strong interfaces, and provide plenty documentation.

Voila.. one plugin system.

EDIT: oh, and to implement the observer pattern is more than to just create a notify object, you'll actually need to have your application use it :)
Link to comment
Share on other sites

The most straightforward way to implement a plugin system is to use php5 interfaces http://us3.php.net/interfaces.

Consider the following:

[code]
<?php
interface Foo
{
  public function getPluginName();
  public function mutateSomeObject(&$obj);
}
?>
[/code]

By using in an interface you are forcing plugins to implement certain methods, in this case getPluginName and mutateSomeObject.

A 3rd party plugin might look something like this:

[code]
<?php
class SomePlugin implements Foo
{
  public function getPluginName()
  {
    return 'MyPlugin';
  }

  public function mutateSomeObject(&$obj)
  {
    $obj->setProperty('foo');
  }
}
?>
[/code]

When you want to act on your plugin you might do something like this:

[code]
<?php
//..
$plugin =& PluginManager::getInstalledPlugin('SomePlugin');
echo 'Loading plugin ' . $plugin->getPluginName() . '...';
$plugin->mutateSomeObject($someObject);
?>
[/code]

Best,

Patrick

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.