cvs: pear /HTML_Progress2/examples/monitor monitorlog.php

From: Date: Mon, 01 Aug 2005 08:20:37 +0000
Subject: cvs: pear /HTML_Progress2/examples/monitor monitorlog.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-33497@lists.php.net to get a copy of this message
farell Mon Aug 1 04:20:37 2005 EDT Modified files: /pear/HTML_Progress2/examples/monitor monitorlog.php Log: example that demonstrate the power of new event listener interface http://cvs.php.net/diff.php/pear/HTML_Progress2/examples/monitor/monitorlog.php?r1=1.2&r2=1.3&ty=u Index: pear/HTML_Progress2/examples/monitor/monitorlog.php diff -u pear/HTML_Progress2/examples/monitor/monitorlog.php:1.2 pear/HTML_Progress2/examples/monitor/monitorlog.php:1.3 --- pear/HTML_Progress2/examples/monitor/monitorlog.php:1.2 Tue Jul 26 12:41:39 2005 +++ pear/HTML_Progress2/examples/monitor/monitorlog.php Mon Aug 1 04:20:36 2005 @@ -1,9 +1,9 @@ <?php /** * Progress2 Monitor with default QF renderer - * and a user callback for logging events. + * and a user listener for logging events. * - * @version $Id: monitorlog.php,v 1.2 2005/07/26 16:41:39 farell Exp $ + * @version $Id: monitorlog.php,v 1.3 2005/08/01 08:20:36 farell Exp $ * @author Laurent Laville <pear@laurent-laville.org> * @package HTML_Progress2 * @subpackage Examples @@ -11,31 +11,47 @@ */ require_once 'HTML/Progress2/Monitor.php'; -function logger($pValue, &$pb) +function getmicrotime($time) +{ + list($usec, $sec) = explode(' ', $time); + return ((float)$usec + (float)$sec); + +} + +function logger(&$notification) { static $time_start; global $pm; - $pb->sleep(); + $notifyName = $notification->getNotificationName(); + $notifyInfo = $notification->getNotificationInfo(); + + if ($notifyName == 'onSubmit') { + $time_start = getmicrotime($notifyInfo['time']); - if (!isset($time_start)) { - $time = explode(' ', microtime()); - $time_start = $time[1] + $time[0]; - - } elseif (fmod($pValue,25) == 0) { - $time = explode(' ', microtime()); - $elapse = $time[1] + $time[0] - $time_start; - $pm->setCaption('%value%% has been reached on %time% sec.', - array('value' => $pValue, 'time' => sprintf('%01.3f',$elapse)) - ); + } elseif ($notifyName == 'onLoad') { + $elapse = getmicrotime($notifyInfo['time']) - $time_start; + printf('script runtime: %f seconds.', $elapse); + + } elseif ($notifyName == 'onChange') { + + if (fmod($notifyInfo['value'], 25) == 0) { + $time = getmicrotime($notifyInfo['time']); + + $elapse = $time - $time_start; + $pm->setCaption('%value%% has been reached on %time% sec.', + array('value' => $notifyInfo['value'], 'time' => sprintf('%01.3f',$elapse)) + ); + } } } + $pm = new HTML_Progress2_Monitor(); $pb =& $pm->getProgressElement(); $pb->setAnimSpeed(100); -$pb->setProgressHandler('logger'); +$pb->addListener('logger'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> @@ -50,7 +66,7 @@ <body> <?php -echo $pm->toHtml(); +$pm->display(); $pm->run(); ?>

« previous php.pear.cvs (#33497) next »