]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/event.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / lib / event.php
index d815ae54bac4a137a2f5b534cc06e8cccba066b3..aa52fa361ca570f5605690fdbd0a3712387a719c 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * utilities for defining and running event handlers
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Event
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @copyright 2008 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2008 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
 /**
  * Class for events
  *
- * This "class" two static functions for managing events in the Laconica code.
+ * This "class" two static functions for managing events in the StatusNet code.
  *
  * @category Event
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  *
  * @todo     Define a system for using Event instances
  */
@@ -54,7 +54,7 @@ class Event {
     /**
      * Add an event handler
      *
-     * To run some code at a particular point in Laconica processing.
+     * To run some code at a particular point in StatusNet processing.
      * Named events include receiving an XMPP message, adding a new notice,
      * or showing part of an HTML page.
      *
@@ -98,7 +98,7 @@ class Event {
      *                 on results of handlers.
      */
 
-    public static function handle($name, $args=array()) {
+    public static function handle($name, array $args=array()) {
         $result = null;
         if (array_key_exists($name, Event::$_handlers)) {
             foreach (Event::$_handlers[$name] as $handler) {
@@ -110,4 +110,40 @@ class Event {
         }
         return ($result !== false);
     }
+
+    /**
+     * Check to see if an event handler exists
+     *
+     * Look to see if there's any handler for a given event, or narrow
+     * by providing the name of a specific plugin class.
+     *
+     * @param string $name Name of the event to look for
+     * @param string $plugin Optional name of the plugin class to look for
+     *
+     * @return boolean flag saying whether such a handler exists
+     *
+     */
+
+    public static function hasHandler($name, $plugin=null) {
+        if (array_key_exists($name, Event::$_handlers)) {
+            if (isset($plugin)) {
+                foreach (Event::$_handlers[$name] as $handler) {
+                    if (get_class($handler[0]) == $plugin) {
+                        return true;
+                    }
+                }
+            } else {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Disables any and all handlers that have been set up so far;
+     * use only if you know it's safe to reinitialize all plugins.
+     */
+    public static function clearHandlers() {
+        Event::$_handlers = array();
+    }
 }