/** * @param Identity $identity * @return mixed * @throws \Exception */ public function auth(Identity $identity) { if (StrUtil::startsWith($identity->channel, ['private-', 'presence-']) && empty($identity->identifier)) { throw new \Exception('Unauthorized', 403); } return parent::verifyThatIdentityCanAccessChannel($identity, str_replace(['private-', 'presence-'], '', $identity->channel)); }
/** * @param Identity $identity * @param $response * @return string signature */ public function validAuthenticationResponse(Identity $identity, $response) { if (StrUtil::startsWith($identity->channel, 'private')) { return $this->pusher->socket_auth($identity->channel, $identity->socketId); } else { return $this->pusher->presence_auth($identity->channel, $identity->socketId, $identity->identifier, $response); } }
/** * @param string $key * @param string $channel * @return array */ protected function getAuthenticationParameters($key, $channel) { if (!StrUtil::contains($key, '*')) { return []; } $pattern = str_replace('\\*', '([^\\.]+)', preg_quote($key)); if (preg_match('/^' . $pattern . '/', $channel, $keys)) { array_shift($keys); return $keys; } return []; }
public function testStringEndsNotWithMultiple() { $result = StrUtil::endsWith('foo-bar', ['foo', 'foo']); $this->assertFalse($result); }