[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/object/ -> observable.class.php (source)

   1  <?php
   2  
   3      
   4  
   5      /**
   6       * \ingroup Core
   7       *
   8       * Implementation of the Observer pattern. Copied/Inspired ;) from
   9       * http://www.phppatterns.com/index.php/article/articleview/27/1/1/.
  10       */
  11       class Observable  {
  12  
  13          /**
  14           * @private
  15           * $observers an array of Observer objects to notify
  16           */
  17          var $observers;
  18  
  19          /**
  20           * @private
  21           * $state store the state of this observable object
  22           */
  23          var $state;
  24  
  25          /**
  26           * Constructs the Observerable object
  27           */
  28          function Observable ()
  29          {
  30              $this->observers=array();
  31          }
  32  
  33          /**
  34           * Calls the update() function using the reference to each
  35           * registered observer - used by children of Observable
  36           * @return void
  37           */
  38          function notifyObservers ()
  39          {
  40              print("notifying observers!");
  41              $observers=count($this->observers);
  42              for ($i=0;$i<$observers;$i++) {
  43                  $this->observers[$i]->update();
  44              }
  45          }
  46  
  47          /**
  48           * Register the reference to an object object
  49           * @return void
  50           */
  51          function addObserver (& $observer)
  52          {
  53              $this->observers[]=& $observer;
  54          }
  55  
  56          /**
  57           * Returns the current value of the state property
  58           * @return mixed
  59           */
  60          function getState ()
  61          {
  62              return $this->state;
  63          }
  64  
  65          /**
  66           * Assigns a value to state property
  67           * @param $state mixed variable to store
  68           * @return void
  69           */
  70          function setState ($state)
  71          {
  72              $this->state=$state;
  73          }
  74      }
  75  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics