/** * Removes a callback for the given $event * @param string $event * @param callback $callback */ public static function unsubscribe($event = null, $callback = null) { if (null === $event) { self::$events = array(); return; } if (!isset(self::$events[$event])) { return; } if (null === $callback) { unset(self::$events[$event]); return; } $id = self::getCallbackHash($callback); // remove all callbacks for specific event unset(self::$events[$event][$id]); }
/** * @covers PubSub::add */ public function testGet() { PubSub::subscribe('my_event', 'global_pub_sub_test_callback'); // all events $this->assertNotEmpty(PubSub::events()); // same priority, different event $this->assertEmpty(PubSub::subscriptions('some_other_event')); // diffent event, no priority distinction $this->assertEmpty(PubSub::subscriptions('some_other_event')); $callbacks = PubSub::subscriptions('my_event'); $this->assertNotEmpty($callbacks); $this->assertEquals('global_pub_sub_test_callback', $callbacks[0]); }