Overview

Packages

  • PubSub

Classes

  • Horde_PubSub
  • Horde_PubSub_Handle
  • Horde_PubSub_Provider
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Publish-Subscribe system based on Phly_PubSub
 4:  * (http://weierophinney.net/matthew/archives/199-A-Simple-PHP-Publish-Subscribe-System.html)
 5:  *
 6:  * Copyright 2008-2011 Matthew Weier O'Phinney
 7:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
 8:  *
 9:  * @category  Horde
10:  * @package   PubSub
11:  * @author    Matthew Weier O'Phinney <mweierophinney@gmail.com>
12:  * @license   New BSD {@link http://www.opensource.org/licenses/bsd-license.php}
13:  */
14: 
15: /**
16:  * Publish-Subscribe handler: unique handle subscribed to a given topic.
17:  *
18:  * @category  Horde
19:  * @package   PubSub
20:  */
21: class Horde_PubSub_Handle
22: {
23:     /**
24:      * PHP callback to invoke
25:      * @var string|array
26:      */
27:     protected $_callback;
28: 
29:     /**
30:      * Topic to which this handle is subscribed
31:      * @var string
32:      */
33:     protected $_topic;
34: 
35:     /**
36:      * Constructor
37:      *
38:      * @param  string $topic Topic to which handle is subscribed
39:      * @param  string|object $context Function name, class name, or object instance
40:      * @param  string|null $handler Method name, if $context is a class or object
41:      */
42:     public function __construct($topic, $context, $handler = null)
43:     {
44:         $this->_topic = $topic;
45: 
46:         if (null === $handler) {
47:             $this->_callback = $context;
48:         } else {
49:             $this->_callback = array($context, $handler);
50:         }
51:     }
52: 
53:     /**
54:      * Get topic to which handle is subscribed
55:      *
56:      * @return string
57:      */
58:     public function getTopic()
59:     {
60:         return $this->_topic;
61:     }
62: 
63:     /**
64:      * Retrieve registered callback
65:      *
66:      * @return string|array
67:      */
68:     public function getCallback()
69:     {
70:         return $this->_callback;
71:     }
72: 
73:     /**
74:      * Invoke handler
75:      *
76:      * @param  array $args Arguments to pass to callback
77:      * @return void
78:      */
79:     public function call(array $args)
80:     {
81:         call_user_func_array($this->getCallback(), $args);
82:     }
83: }
84: 
API documentation generated by ApiGen