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 * Observable Subject pattern interface for Joomla
14 *
15 * To make a class and its inheriting classes observable:
16 * 1) add: implements JObservableInterface
17 * to its class
18 *
19 * 2) at the end of the constructor, add:
20 * // Create observer updater and attaches all observers interested by $this class:
21 * $this->_observers = new JObserverUpdater($this);
22 * JObserverMapper::attachAllObservers($this);
23 *
24 * 3) add the function attachObserver below to your class to add observers using the JObserverUpdater class:
25 * public function attachObserver(JObserverInterface $observer)
26 * {
27 * $this->_observers->attachObserver($observer);
28 * }
29 *
30 * 4) in the methods that need to be observed, add, e.g. (name of event, params of event):
31 * $this->_observers->update('onBeforeLoad', array($keys, $reset));
32 *
33 * @since 3.1.2
34 */
35 interface JObservableInterface
36 {
37 /**
38 * Adds an observer to this JObservableInterface instance.
39 * Ideally, this method should be called fron the constructor of JObserverInterface
40 * which should be instanciated by JObserverMapper.
41 * The implementation of this function can use JObserverUpdater
42 *
43 * @param JObserverInterface $observer The observer to attach to $this observable subject
44 *
45 * @return void
46 *
47 * @since 3.1.2
48 */
49 public function attachObserver(JObserverInterface $observer);
50 }
51