Source for file mapper.php

Documentation is available at mapper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Observer
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Observer mapping pattern implementation for Joomla
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Observer
  17.  * @link        http://docs.joomla.org/JObserverMapper
  18.  * @since       3.1.2
  19.  */
  20. {
  21.     /**
  22.      * Array: array( JObservableInterface_classname => array( JObserverInterface_classname => array( paramname => param, .... ) ) )
  23.      *
  24.      * @var    array 
  25.      * @since  3.1.2
  26.      */
  27.     protected static $observations array();
  28.  
  29.     /**
  30.      * Adds a mapping to observe $observerClass subjects with $observableClass observer/listener, attaching it on creation with $params
  31.      * on $observableClass instance creations
  32.      *
  33.      * @param   string         $observerClass    The name of the observer class (implementing JObserverInterface)
  34.      * @param   string         $observableClass  The name of the observable class (implementing JObservableInterface)
  35.      * @param   array|boolean $params           The params to give to the JObserverInterface::createObserver() function, or false to remove mapping
  36.      *
  37.      * @return  void 
  38.      *
  39.      * @since   3.1.2
  40.      */
  41.     public static function addObserverClassToClass($observerClass$observableClass$params array())
  42.     {
  43.         if ($params !== false)
  44.         {
  45.             static::$observations[$observableClass][$observerClass$params;
  46.         }
  47.         else
  48.         {
  49.             unset(static::$observations[$observableClass][$observerClass]);
  50.         }
  51.     }
  52.  
  53.     /**
  54.      * Attaches all applicable observers to an $observableObject
  55.      *
  56.      * @param   JObservableInterface  $observableObject  The observable subject object
  57.      *
  58.      * @return  void 
  59.      *
  60.      * @since   3.1.2
  61.      */
  62.     public static function attachAllObservers(JObservableInterface $observableObject)
  63.     {
  64.         $observableClass get_class($observableObject);
  65.  
  66.         while ($observableClass != false)
  67.         {
  68.             // Attach applicable Observers for the class to the Observable subject:
  69.             if (isset(static::$observations[$observableClass]))
  70.             {
  71.                 foreach (static::$observations[$observableClassas $observerClass => $params)
  72.                 {
  73.                     // Attach an Observer to the Observable subject:
  74.                     /**
  75. /**
  76.                      * @var JObserverInterface $observerClass 
  77.                      */
  78.                     $observerClass::createObserver($observableObject$params);
  79.                 }
  80.             }
  81.  
  82.             // Get parent class name (or false if none), and redo the above on it:
  83.             $observableClass get_parent_class($observableClass);
  84.         }
  85.     }
  86. }

Documentation generated on Tue, 19 Nov 2013 15:07:36 +0100 by phpDocumentor 1.4.3