Table of Contents

Public Methods

or, Comments as a Gadget

Author: Jon Wood jon@jellybob.co.uk
Date: 22 April 2005

This proposal is currently in progress, feel free to make changes wherever.

Summary

This started out as just providing comments as their own gadget, but the same sort of thing could be used in other places. Comments will be used as an example.

Public methods will allow a gadget to advertise that it provides a certain feature, for example “comments”, which will have a defined API which is the same whatever gadget is providing it.

Implementation

In a gadgets info it should add a line to their gadget info stating that they provide a function API, such as:

<gadget>
    <name lang="en">Comments</name>
    <description lang="en">A funky comment system for Jaws.</description>
    <version>0.1</version>
    <provides>comment</provides>
</gadget>

This states that the gadget implements the “comment” API, and anything that wants to use that can do so.

When they want to use this other gadgets will make a call like:

<?php
// Get an object which implements the comment API.
// It'll probably be somewhere other than JawsGadget, not sure where yet though.
$comments =& JawsGadget::GetAPI('comment');
 
// Get any comments for Blog entry 32
$comments->Get('Blog', 32);
?>

GetAPI() will choose which gadget to use based on user preferences - for now a key in the registry, but possibly something else if someone thinks of it.

/api/comment = "Comments"

Will say that the “comment” API will be provided by “Comments”.

A class which implements an API should provide a GetAPI($api) method which will be called to get the object which provides this API - so long as it provides the right methods this can be whatever type of object the gadget likes.

 
  /var/www/wiki/htdocs/data/jaws/proposals/public_methods.txt · Last modified: 2007/11/02 16:27