/** * @group utils */ public function testEndsWith() { $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo-pnpres", "-pnpres")); $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo.bar-pnpres", "-pnpres")); $this->assertTrue(\Pubnub\PubnubUtil::string_ends_with("foo.*-pnpres", "-pnpres")); $this->assertFalse(\Pubnub\PubnubUtil::string_ends_with("foo", "-pnpres")); $this->assertFalse(\Pubnub\PubnubUtil::string_ends_with("foo.bar", "-pnpres")); }
/** * Check if wc message should be passed to user callback * * @param string $channel * @param string $group * @param array $subscribe * @param array $presence * @param PubnubLogger $logger * @return bool passed if message should be passed to user callback */ public static function shouldWildcardMessageBePassedToUserCallback($channel, $group, $subscribe, $presence, $logger) { // if presence message while only subscribe if (PubnubUtil::string_ends_with($channel, static::PRESENCE_SUFFIX) && !in_array($group, $presence)) { $logger->debug("WC presence message on " . $channel . " while is not subscribe for presence"); return false; // if subscribe message while only presence } elseif (!PubnubUtil::string_ends_with($channel, static::PRESENCE_SUFFIX) && !in_array($group, $subscribe)) { $logger->debug("WC subscribe message on " . $channel . " while is not subscribe for messages"); return false; } else { return true; } }