Okay, since we didn’t get much discussion about the plugin system on our conversation last week, I thought it’d be best to put a topic up here so we can share ideas and get talking about how it’s going to work.
As far as Kev’s plugin, I like the idea, but I don’t think that we should take the ‘app in an app’ route. I just think that embedding controllers, models and views into a plugin causes a lot of problems, and the advantages aren’t that better than using a more conventional system. For one thing, a developer may want to use a different controller for handling sessions, and this would require the developer going into the plugin itself to modify the files – which defeats the purpose of a plugin.
A plugin should be:
· An extension of functionality – it should provide a way of doing something either not possible with current tools or it should simplify the process
· Abstract – a plugin can’t depend on anything application specific ie. Controller names, Routing structure
· Independent – a plugin should not be aware of any other plugins in the system – it should not rely on any other plugins or have any internal dependencies
· Structured – a set of conventions will be put in place (including, but not limited to file/folder names and method names/parameters) and these conventions should be followed as much as possible.
· Reliable – a testing framework will be put in place for the plugin API, and plugin developers will be encouraged to test the plugin wherever possible.
Likewise, the API should be:
· Conventional – any conventions already in the framework should remain for continuity
· Modular – the API should be able to dissipate common areas of framework functionality (Request, I/O, DBA etc.) into classes and interfaces for the developer to extend, allowing the framework’s functionality to change.
· Conscious – although extendibility is encouraged, the API should protect the core of the framework to make it as safe as possible and not let plugins interfere with the major framework functions. An example of this is to prevent a plugin from changing the loading mechanism.
I believe that a plugin’s file structure should look something like this:
/plugins –
/plugin1 –
_init.php
_close.php
_meta.php
/lib
–
Plugin1.class.php
another_file.php
/recess –
Plugin1.Annotations.class.php
Plugin1.Model.class.php
Plugin1.Controller.class.php
/anotherplugin –
_meta.php
/lib
–
AnotherPlugin.class.php
/recess –
AnotherPlugin.Annotations.class.php
AnotherPlugin.SomeFrameworkClass.class.php
A few notes:
· _init.php gets called before any other file in the plugin. It allows the plugin to initialize any constants, variables or anything else it may need to operate.
· _close.php gets called after the plugin has been fully loaded and the response has been sent to the browser, just before the core system shuts down. It should remain in the same scope as _init.php so it can reverse the changes made.
· _meta.php contains any meta information about the plugin, including author, URL, description, licenses/copyright etc.
· The plugin’s core class will be held in PluginName.class.php in the /lib directory. This will be the only class that gets loaded directly, and will therefore need to present an interface to the user’s app, which can then interact with other classes/files.
· The /recess directory holds any system extensions/additions. The convention for files is PluginName.ClassName.class.php.
· Not all files are required – only the _meta.php and lib/PluginName.class.php files are needed, this will make creating plugins easier and cleaner.
I’m sorry that’s a lot to digest, and not particularly organised, as I’ve simply spewed my ideas on the email and hoped it is coherent, but it should give us a lot to discuss and should present some interesting ideas.
Catch you later,
Jamie
Jamie Rumbelow Designer / Developer / Writer / Speaker
http://www.jamierumbelow.net | +44 (0)7956 363875 | jamie (at) jamierumbelow (dot) net
> · Independent – a plugin should not be aware of any other
> plugins in the system – it should not rely on any other plugins or
> have any internal dependencies
Only had time to skim this msg atm, but as discussed in IRC, a
Requires/Provides notation for plugins seems very acceptable to me. The
framework will keep track of whether dependencies are met and die
appropriately if they're not. Plugins are as likely to need other code
as anything else is.
(And I promise it's not just that I like disagreeing with you, Jamie.)
--
Joshua Paine
LetterBlock: Web applications built with joy
http://letterblock.com/
301-576-1920
· Abstract – a plugin can’t depend on anything application specific ie. Controller names, Routing structure ... Agree and disagree. Agree from a hard dependency point of view, i.e., a plugin should not have a dependency on anything specific in an application. Disagree from a configurable point of view, i.e., an application can configure a plugin with settings a plugin needs (i.e. the route to an unauthorized request, call-backs on a model or controller, etc).
· I Independent – a plugin should not be aware of any other plugins in the system – it should not rely on any other plugins or have any internal dependencies In the near-term I agree with this. In the far-term I can envision plugin dependencies. Not worth getting hung-up at this stage in discussion.
· Structured – Agreed!
· Reliable – Agreed! And applications need a better testing infrastructure as well. Is anyone a PHPUnit expert? Would love to talk further about how best to structure application-level and plugin-level tests.