| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* a class for handling the publishing of data
|
|
|
4 |
*
|
|
|
5 |
* phpDocumentor :: automatic documentation generator
|
|
|
6 |
*
|
|
|
7 |
* PHP versions 4 and 5
|
|
|
8 |
*
|
|
|
9 |
* Copyright (c) 2000-2007 Kellin, Joshua Eichorn
|
|
|
10 |
*
|
|
|
11 |
* LICENSE:
|
|
|
12 |
*
|
|
|
13 |
* This library is free software; you can redistribute it
|
|
|
14 |
* and/or modify it under the terms of the GNU Lesser General
|
|
|
15 |
* Public License as published by the Free Software Foundation;
|
|
|
16 |
* either version 2.1 of the License, or (at your option) any
|
|
|
17 |
* later version.
|
|
|
18 |
*
|
|
|
19 |
* This library is distributed in the hope that it will be useful,
|
|
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
22 |
* Lesser General Public License for more details.
|
|
|
23 |
*
|
|
|
24 |
* You should have received a copy of the GNU Lesser General Public
|
|
|
25 |
* License along with this library; if not, write to the Free Software
|
|
|
26 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
27 |
*
|
|
|
28 |
* @category ToolsAndUtilities
|
|
|
29 |
* @package phpDocumentor
|
|
|
30 |
* @author Kellin <passionplay@hotmail.com>
|
|
|
31 |
* @author Joshua Eichorn <jeichorn@phpdoc.org>
|
|
|
32 |
* @copyright 2000-2007 Kellin, Joshua Eichorn
|
|
|
33 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
34 |
* @version CVS: $Id: Publisher.inc 244033 2007-10-11 03:30:34Z ashnazg $
|
|
|
35 |
* @link http://www.phpdoc.org
|
|
|
36 |
* @link http://pear.php.net/PhpDocumentor
|
|
|
37 |
* @since 0.1
|
|
|
38 |
* @todo CS cleanup - change package to PhpDocumentor
|
|
|
39 |
*/
|
|
|
40 |
/**
|
|
|
41 |
* a class for handling the publishing of data
|
|
|
42 |
*
|
|
|
43 |
* @category ToolsAndUtilities
|
|
|
44 |
* @package phpDocumentor
|
|
|
45 |
* @author Kellin <passionplay@hotmail.com>
|
|
|
46 |
* @author Joshua Eichorn <jeichorn@phpdoc.org>
|
|
|
47 |
* @copyright 2000-2007 Kellin, Joshua Eichorn
|
|
|
48 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
|
|
49 |
* @version Release: 1.4.3
|
|
|
50 |
* @link http://www.phpdoc.org
|
|
|
51 |
* @link http://pear.php.net/PhpDocumentor
|
|
|
52 |
* @todo CS cleanup - change package to PhpDocumentor
|
|
|
53 |
*/
|
|
|
54 |
class Publisher
|
|
|
55 |
{
|
|
|
56 |
/**#@+
|
|
|
57 |
* @var array
|
|
|
58 |
*/
|
|
|
59 |
/**
|
|
|
60 |
* Array of references objects that have Subscribed to this publisher
|
|
|
61 |
*/
|
|
|
62 |
var $subscriber = array();
|
|
|
63 |
|
|
|
64 |
var $tokens = array();
|
|
|
65 |
|
|
|
66 |
var $pushEvent = array();
|
|
|
67 |
var $popEvent = array();
|
|
|
68 |
/**#@-*/
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
* Adds a subscriber to the {@link $subscriber} array().
|
|
|
73 |
* if $event is '*', the publisher will use $object as the default event handler
|
|
|
74 |
*
|
|
|
75 |
* @param integer $event see {@link Parser.inc} PARSER_EVENT_* constants
|
|
|
76 |
* @param class &$object any class that has a HandleEvent() method like
|
|
|
77 |
* {@link phpDocumentor_IntermediateParser::HandleEvent()}
|
|
|
78 |
* or {@link Classes::HandleEvent()}
|
|
|
79 |
*
|
|
|
80 |
* @return void
|
|
|
81 |
* @todo CS Cleanup - there's no way I can get the &$object desc under 85 chars
|
|
|
82 |
*/
|
|
|
83 |
function subscribe($event, &$object)
|
|
|
84 |
{
|
|
|
85 |
$this->subscriber[$event] =& $object;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
/**
|
|
|
89 |
* Publish an event
|
|
|
90 |
*
|
|
|
91 |
* @param integer $event see {@link Parser.inc} PARSER_EVENT_* constants
|
|
|
92 |
* @param mixed $data anything the subscribed event handler is expecting
|
|
|
93 |
*
|
|
|
94 |
* @return void
|
|
|
95 |
*/
|
|
|
96 |
function publishEvent($event,$data)
|
|
|
97 |
{
|
|
|
98 |
|
|
|
99 |
// see if there is a specific event handler
|
|
|
100 |
if (!empty($this->subscriber[$event])) {
|
|
|
101 |
$this->subscriber[$event]->HandleEvent($event, $data);
|
|
|
102 |
} else if (isset($this->subscriber['*'])
|
|
|
103 |
&& is_object($this->subscriber['*'])) {
|
|
|
104 |
// check to see if a generic handler exists
|
|
|
105 |
|
|
|
106 |
$this->subscriber['*']->HandleEvent($event, $data);
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
?>
|