[geeklog-devel] GL2 event model

Tom Willett tomw at pigstye.net
Wed Jul 21 18:10:55 EDT 2004


Let me get this straight.

GL2 Core would make the MySubjectObserverClass

$obs = new MySubjectObserverClass;

then the plugin would register by somehow getting the reference to the 
MySubjectOvserverClass and register itself as a listener

$obs->addListner($MyPlugin);
or
$obs->addListener($MyPlugin, $events);
etc

Then when a event happened GL2 Core or a plugin could notify the plugins

$obs->notifyAll($event)

Do I have this about right?

--
Tom Willett
tomw at pigstye.net

---------- Original Message -----------
From: Tony Bibbs <tony at tonybibbs.com>
To: geeklog-devel at lists.geeklog.net
Sent: Wed, 21 Jul 2004 16:31:57 -0500
Subject: [geeklog-devel] GL2 event model

> The plugin API for GL2 that Vinny has drafted if surprisingly small 
> because we are introducing an event based model.  Essentially, the GL2 
> and all plugins have the option to register events that others can 
> listen to.  To implement this I recommend an observer/observable design 
> pattern similar to the example below.  A few things that need 
> discussion.  First, the example below allows listening only at the 
> object level.  The alternative is the force listening at the event level 
> (in otherwords, addListener would take as a second arg an array of 
> events the object listens to).  Any preference?  General questions?:
> 
> class MySubjectObserverClass {
>    private $listeners = array();
>    private $listernerNextID  =  0;
> 
>    // Alternative names: register, subscribe...
>    public function addListerner(&$obj)
>    {
>        $this->_listerners[] =& $obj;
>       return $this->listernerNextID++;
>    }
> 
>    // Alternative name: unregister, unsubscribe...
>    public function removeListerner($id,'even't)
>    {
>         unset($this->listerners[$id]);
>    }
> 
>    // Alternative name: broadcast...
>    public function notifyAll($event)
>    {
>        foreach ($this->listerners as $id => $obj)
>        {
>            $this->listerners[$id]->notify($event, $this);
>        }
>    }
> 
>    // Alternative name: listen...
>    function notify($event, &$obj)
>    {
>         switch (get_class($obj)) {
>             case 'blah':
>                ...
>        }
>    }
> }
> 
> _______________________________________________
> geeklog-devel mailing list
> geeklog-devel at lists.geeklog.net
> http://lists.geeklog.net/listinfo/geeklog-devel
------- End of Original Message -------




More information about the geeklog-devel mailing list