/** * @dataProvider providerGetChannelsetId */ public function testGetChannelsetId($id, $name) { $this->assertEquals($id, InstructionControl::getChannelsetId($name)); $g = genSaneGuid(); $j = InstructionControl::getChannelsetId($g); $k = InstructionControl::getChannelsetId($g); $this->assertEquals($k, $j); return $k; }
/** * Returns the Id of a Channelset. * * @param string $name The name of a Channelset. * @return int The Id of a Channelset */ protected function getChannelsetId($name) { if (!$this->getSessionVariable('KNOWN_CHANNELSET')) { $this->setSessionVariable('KNOWN_CHANNELSET', array()); } if (in_array($name, $this->getSessionVariable('KNOWN_CHANNELSET'))) { $ar = $this->getSessionVariable('KNOWN_CHANNELSET'); return $ar[$name]; } $sess = $this->getSessionVariable('KNOWN_CHANNELSET'); $sess[$name] = InstructionControl::getChannelsetId($name); $this->setSessionVariable('KNOWN_CHANNELSET', $sess); return $sess[$name]; }
/** * This function will send an Instruction (properties) to the other clients * on the webpage. * * @param string $channelset The Channelset name * @param string $channelId The Id of the Channel * @param array The output from InstructionControl::generateReturnDocument() * * @see InstructionControl::generateReturnDocument() */ public static function notifyOtherClientsApe($channelset, $channelId, $data) { $APEserver = 'http://' . self::getOption('APE_CONFIG_SERVER') . '/?'; $APEPassword = '******'; if ($channelId === null) { $channelsetId = InstructionControl::getChannelsetId($channelset); $channelId = InstructionControl::getChannelId($channelsetId, 'main'); } $channelName = self::getChannelname($channelId); $cmd = array(array('cmd' => 'inlinepush', 'params' => array('password' => $APEPassword, 'raw' => 'instruction', 'channel' => $channelset . '_' . $channelName, 'data' => $data))); $url = $APEserver . rawurlencode(json_encode($cmd)); $answerJson = file_get_contents($url); $answer = array_pop(json_decode($answerJson, true)); if (!$answer || $answer['data']['value'] != 'ok') { throw new Exception("Could not notify other clients " . print_r($cmd, 1) . print_r($answer, 1)); } }