On Wed, Oct 5, 2011 at 13:05, Cor Bosman <[email protected]> wrote:
> Ive been developing some internal plugins that communicate with a REST/json
> api. Ive written some classes that do the actual work, and i find myself
> including those in multiple plugins. This seems like it could be done better.
>
> What would be really cool is if one could extend RC by adding not just
> plugins, but also classes. So you could do:
> $rcmail->myclass->myfunction(….). That way, I could add a class once, and use
> it from multiple plugins. This could be useful for plugin developers as well,
> as we could see stuff like Zend or other interesting libraries appear in
> roundcube for plugins to use.
>
> Maybe this is already possible, and if so, could someone explain how?
Without having tested it, this should actually be possible with a
plugin defining these classes and other plugins using require_plugin()
to include them.
You can for example create a library plugin which simply extends the
include path in order to make autoloading find classes in that
particular plugin directory:
class corlib extends rcube_plugin
{
public function init() {
$include_path = $this->home . PATH_SEPARATOR . ini_get('include_path');
set_include_path($include_path);
}
}
And since PHP allows one to add unknown members to an object, that lib
plugin could even instantiate certain objects and attach them to
rcmail just as you requested:
class corlib extends rcube_plugin
{
public function init() {
require_once($this->home . '/lib/myclass.php');
$rcmail = rcmail::get_instance();
$rcmail->myclass = new myclass();
}
}
And other plugins can access the library stuff by using
$this->require_plugin('corlib');
I hope this helps...
~Thomas
_______________________________________________
List info: http://lists.roundcube.net/dev/
BT/8f4f07cd