Use of Event_Dispatcher package
| From: | Philippe Jausions | Date: | Mon, 28 Feb 2005 18:34:28 +0000 |
| Subject: | Use of Event_Dispatcher package | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-36422@lists.php.net to get a copy of this message | ||
Hi,
I need to write a PEAR package for the File Alteration Monitor (FAM) extension. Since it deals with event and notification, I thought I could leverage the work done on the new Event_Dispatch package.
Now, the problem is that I would need to observe when objects register themselves to the dispatcher so I can tell the FAM daemon to monitor the file resource (files, directory or file collection.)
I'd like to use the addObserver() with a syntax similar as:
To monitor a single file:
addObserver($callback, 'file://file_name_to_monitor',
'File_Monitor_Event');To monitor a directory: addObserver($callback, 'dir://folder_name_to_monitor',
'File_Monitor_Event');To monitor a collection: addObserver($callback, 'coll://folder_name?depth=3&mask=*.log',
'File_Monitor_Event_Create');So obviously there are several problems: 1. Event_Dispatcher doesn't seem to have a built-in notification for addObserver and so on... 2. FAM supports more features such as Suspend/Resume, event pull. 3. The collection syntax may need adjustment to allow for real shell mask filters. Given how PHP and FAM work, most use of FAM will be "request and wait". So sample code would be: <?php [...] require_once 'Event/Dispatcher.php'; require_once 'File/Monitor.php'; $dispatcher =& Event_Dispatcher::getInstance(); $fileMonitor =& File_Monitor::singleton($dispatcher); $dispatcher->addObserver(array(&$some_object, 'fileChanged'), 'file://my/file/to/monitor', 'File_Monitor_Event'); // Start infinite loop. Its stopping would occur if: // 1. $some_object directly stops it (although, that defies a little
// bit the idea of observable/observer// 2. No more resources to monitor, i.e. $some_object calls a
// removeObserver()$fileMonitor->start(); [...] ?> What do you all think of this? And of course, do you think having the dispatcher as an self-observeable object a workable solution. Thanks, -Philippe