1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage Observer
5 *
6 * @copyright Copyright (C) 2005 - 2017 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 pattern interface for Joomla
14 *
15 * A class that wants to observe another class must:
16 *
17 * 1) Add: implements JObserverInterface
18 * to its class
19 *
20 * 2) Implement a constructor, that can look like this:
21 * public function __construct(JObservableInterface $observableObject)
22 * {
23 * $observableObject->attachObserver($this);
24 * $this->observableObject = $observableObject;
25 * }
26 *
27 * 3) and must implement the instanciator function createObserver() below, e.g. as follows:
28 * public static function createObserver(JObservableInterface $observableObject, $params = array())
29 * {
30 * $observer = new self($observableObject);
31 * $observer->... = $params['...']; ...
32 * return $observer;
33 * }
34 *
35 * 4) Then add functions corresponding to the events to be observed,
36 * E.g. to respond to event: $this->_observers->update('onBeforeLoad', array($keys, $reset));
37 * following function is needed in the obser:
38 * public function onBeforeLoad($keys, $reset) { ... }
39 *
40 * 5) Finally, the binding is made outside the observable and observer classes, using:
41 * JObserverMapper::addObserverClassToClass('ObserverClassname', 'ObservableClassname', array('paramName' => 'paramValue'));
42 * where the last array will be provided to the observer instanciator function createObserver.
43 *
44 * @since 3.1.2
45 */
46 interface JObserverInterface
47 {
48 /**
49 * Creates the associated observer instance and attaches it to the $observableObject
50 *
51 * @param JObservableInterface $observableObject The observable subject object
52 * @param array $params Params for this observer
53 *
54 * @return JObserverInterface
55 *
56 * @since 3.1.2
57 */
58 public static function createObserver(JObservableInterface $observableObject, $params = array());
59 }
60