Default observer

Overview

This example will run a progress bar with the default observer pattern
It will generates a storable representation of each progress bar changes.

Screenshot

sample screenshot

And the file progress_observer.log will contents:

sample screenshot

Demonstration

Give it a try

Dependencies

This example requires mandatory resources :

And also but optional :

Explains step by step

The progress meter wait 200ms (line 27) between each step of 10% (line 28).

There are 10 cells with default values:

Property Value Default
active-color   #006600
inactive-color   #CCCCCC
width   15
height   20
spacing   2
See also :

Surrounded by a solid 2 pixels border (lines 35-36):

Property Value Default
class   progressBorder%s
width 2 0
style   solid
color   #000000
See also :

Source Code

  1. <?php
  2. /**
  3. * A basic observer for progress meter.
  4. *
  5. * @version    $Id: observer1.php,v 1.4 2006/05/24 08:41:45 farell Exp $
  6. * @author     Laurent Laville <pear@laurent-laville.org>
  7. * @package    HTML_Progress2
  8. * @subpackage Examples
  9. * @access     public
  10. */
  11. require_once 'HTML/Progress2.php';
  12.  
  13. // Observer that record serialized event datas
  14. function myObserver(&$notification)
  15. {
  16.     $notifyName = $notification->getNotificationName();
  17.     $notifyInfo = $notification->getNotificationInfo();
  18.  
  19.     $info = array_merge(array('event' => $notifyName), $notifyInfo);
  20.     $msg = serialize($info);
  21.     error_log ("$msg \n", 3, 'progress_observer.log');
  22. }
  23.  
  24. // 1. Creates progress meter
  25. $pb = new HTML_Progress2();
  26. $pb->setComment('Basic Observer Progress2 example');
  27. $pb->setAnimSpeed(200);
  28. $pb->setIncrement(10);
  29.  
  30. // 2. Attach an observer
  31. $pb->addListener('myObserver');
  32.  
  33. // 3. Changes look-and-feel of progress meter
  34. //    ( border: 2px, solid, #000000 )
  35. $pb->setBorderPainted(true);
  36. $pb->setBorderAttributes('width=2');
  37. ?>
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  39.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  40. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  41. <head>
  42. <title>Default Observer Progress2 example</title>
  43. <style type="text/css">
  44. <!--
  45. <?php echo $pb->getStyle(); ?>
  46.  
  47. body {
  48.     background-color: #FFFFFF;
  49. }
  50.  -->
  51. </style>
  52. <?php echo $pb->getScript(false); ?>
  53. </head>
  54. <body>
  55.  
  56. <?php
  57. $pb->display();
  58. $pb->run();
  59. ?>
  60.  
  61. </body>
  62. </html>