/** * @param string $uri * @param array|null $headers OPTIONAL * @param array|null $server * @param CM_Model_User|null $viewer */ public function __construct($uri, array $headers = null, array $server = null, CM_Model_User $viewer = null) { if (null !== $headers) { $this->_headers = array_change_key_case($headers); } if (null !== $server) { $this->_server = array_change_key_case($server); } $this->setUri($uri); if ($sessionId = $this->getCookie('sessionId')) { if ($this->_session = CM_Session::findById($sessionId)) { $this->_session->start(); } } if ($viewer) { $this->_viewer = $viewer; } self::$_instance = $this; }
/** * @param string $uri * @param array|null $headers OPTIONAL * @param array|null $server * @param CM_Model_User|null $viewer * @throws CM_Exception * @throws CM_Exception_Invalid */ public function __construct($uri, array $headers = null, array $server = null, CM_Model_User $viewer = null) { if (null !== $headers) { $this->_headers = array_change_key_case($headers); } if (null !== $server) { foreach ($server as &$serverValue) { if (is_string($serverValue)) { $serverValue = CM_Util::sanitizeUtf($serverValue); } } $this->_server = array_change_key_case($server); } $uri = CM_Util::sanitizeUtf((string) $uri); $this->setUri($uri); if ($sessionId = $this->getCookie('sessionId')) { $this->setSession(CM_Session::findById($sessionId)); } if ($viewer) { $this->_viewer = $viewer; } self::$_instance = $this; }
public function testFindById() { $session = new CM_Session(); $session->set('foo', 'bar'); $session->write(); $this->assertEquals($session, CM_Session::findById($session->getId())); $this->assertNull(CM_Session::findById('foo')); $this->assertNull(CM_Session::findById('')); }
/** * @param string $message * @throws CM_Exception_Invalid */ public function onRedisMessage($message) { $message = CM_Params::jsonDecode($message); $type = $message['type']; $data = $message['data']; switch ($type) { case 'subscribe': $channel = $data['channel']; $clientKey = $data['clientKey']; $start = time(); $data = CM_Params::factory((array) $data['data'], true); $user = null; if ($data->has('sessionId')) { if ($session = CM_Session::findById($data->getString('sessionId'))) { $user = $session->getUser(false); } } $this->_subscribe($channel, $clientKey, $start, $user); break; case 'unsubscribe': $channel = $data['channel']; $clientKey = $data['clientKey']; $this->_unsubscribe($channel, $clientKey); break; case 'message': break; default: throw new CM_Exception_Invalid('Invalid socket-redis event type'); } }
/** * @param string $streamName * @param string $clientKey * @param int $start * @param string $data * @throws CM_Exception_NotAllowed */ public function subscribe($streamName, $clientKey, $start, $data) { $streamName = (string) $streamName; $clientKey = (string) $clientKey; $start = (int) $start; $data = (string) $data; $user = null; $params = CM_Params::factory(CM_Params::jsonDecode($data), true); if ($params->has('sessionId')) { if ($session = CM_Session::findById($params->getString('sessionId'))) { $user = $session->getUser(false); } } /** @var CM_Model_StreamChannel_Abstract $streamChannel */ $streamChannel = CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamName, $this->getType()); if (!$streamChannel) { throw new CM_Exception_NotAllowed(); } try { CM_Model_Stream_Subscribe::createStatic(array('streamChannel' => $streamChannel, 'user' => $user, 'start' => $start, 'key' => $clientKey)); } catch (CM_Exception $ex) { throw new CM_Exception_NotAllowed('Cannot subscribe: ' . $ex->getMessage()); } }