]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - vendor/nmred/kafka-php/src/Kafka/Protocol/Fetch/Helper/Helper.php
MediaWiki 1.30.2
[autoinstalls/mediawiki.git] / vendor / nmred / kafka-php / src / Kafka / Protocol / Fetch / Helper / Helper.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3 // +---------------------------------------------------------------------------
4 // | SWAN [ $_SWANBR_SLOGAN_$ ]
5 // +---------------------------------------------------------------------------
6 // | Copyright $_SWANBR_COPYRIGHT_$
7 // +---------------------------------------------------------------------------
8 // | Version  $_SWANBR_VERSION_$
9 // +---------------------------------------------------------------------------
10 // | Licensed ( $_SWANBR_LICENSED_URL_$ )
11 // +---------------------------------------------------------------------------
12 // | $_SWANBR_WEB_DOMAIN_$
13 // +---------------------------------------------------------------------------
14
15 namespace Kafka\Protocol\Fetch\Helper;
16
17 /**
18 +------------------------------------------------------------------------------
19 * Kafka protocol since Kafka v0.8
20 +------------------------------------------------------------------------------
21 *
22 * @package
23 * @version $_SWANBR_VERSION_$
24 * @copyright Copyleft
25 * @author $_SWANBR_AUTHOR_$
26 +------------------------------------------------------------------------------
27 */
28
29 class Helper
30 {
31     // {{{ members
32
33     /**
34      * helper object
35      */
36     private static $helpers = array();
37
38     // }}}
39     // {{{ functions
40     // {{{ public staitc function registerHelper()
41
42     /**
43      * register helper
44      *
45      * @param string $key
46      * @param \Kafka\Protocol\Fetch\Helper\HelperAbstract $helper
47      * @static
48      * @access public
49      * @return void
50      */
51     public static function registerHelper($key, $helper = null)
52     {
53         if (is_null($helper)) {
54             $className = '\\Kafka\\Protocol\\Fetch\\Helper\\' . $key;
55             if (!class_exists($className)) {
56                 throw new \Kafka\Exception('helper is not exists.');
57             }
58             $helper = new $className();
59         }
60
61         if ($helper instanceof \Kafka\Protocol\Fetch\Helper\HelperAbstract) {
62             self::$helpers[$key] = $helper;
63         } else {
64             throw new \Kafka\Exception('this helper not instance of `\Kafka\Protocol\Fetch\Helper\HelperAbstract`');
65         }
66     }
67
68     // }}}
69     // {{{ public staitc function unRegisterHelper()
70
71     /**
72      * unregister helper
73      *
74      * @param string $key
75      * @static
76      * @access public
77      * @return void
78      */
79     public static function unRegisterHelper($key)
80     {
81         if (isset(self::$helpers[$key])) {
82             unset(self::$helpers[$key]);
83         }
84     }
85
86     // }}}
87     // {{{ public static function onStreamEof()
88
89     /**
90      * on stream eof call
91      *
92      * @param string $streamKey
93      * @static
94      * @access public
95      * @return void
96      */
97     public static function onStreamEof($streamKey)
98     {
99         if (empty(self::$helpers)) {
100             return;
101         }
102
103         foreach (self::$helpers as $key => $helper) {
104             if (method_exists($helper, 'onStreamEof')) {
105                 $helper->onStreamEof($streamKey);
106             }
107         }
108     }
109
110     // }}}
111     // {{{ public static function onTopicEof()
112
113     /**
114      * on topic eof call
115      *
116      * @param string $topicName
117      * @static
118      * @access public
119      * @return void
120      */
121     public static function onTopicEof($topicName)
122     {
123         if (empty(self::$helpers)) {
124             return;
125         }
126
127         foreach (self::$helpers as $key => $helper) {
128             if (method_exists($helper, 'onTopicEof')) {
129                 $helper->onStreamEof($topicName);
130             }
131         }
132     }
133
134     // }}}
135     // {{{ public static function onPartitionEof()
136
137     /**
138      * on partition eof call
139      *
140      * @param \Kafka\Protocol\Fetch\Partition $partition
141      * @static
142      * @access public
143      * @return void
144      */
145     public static function onPartitionEof($partition)
146     {
147         if (empty(self::$helpers)) {
148             return;
149         }
150
151         foreach (self::$helpers as $key => $helper) {
152             if (method_exists($helper, 'onPartitionEof')) {
153                 $helper->onPartitionEof($partition);
154             }
155         }
156     }
157
158     // }}}
159     // }}}
160 }