/** * @return string[] */ public function getVariables() { if (!$this->_has('variables')) { return array(); } $variablesEncoded = $this->_get('variables'); return CM_Params::jsonDecode($variablesEncoded); }
public function testProcessingInvalidMethod() { $body = CM_Params::jsonEncode(['method' => 'foo']); $request = new CM_Http_Request_Post('/rpc/' . CM_Site_Abstract::factory()->getType(), null, null, $body); $response = new CM_Http_Response_RPC($request, $this->getServiceManager()); $response->process(); $responseData = CM_Params::jsonDecode($response->getContent()); $this->assertSame(['error' => ['type' => 'CM_Exception_InvalidParam', 'msg' => 'Internal server error', 'isPublic' => false]], $responseData); }
/** * @param CM_Frontend_Environment $environment * @param string $userInput * @throws CM_Exception_FormFieldValidation * @return CM_Model_Location */ public function validate(CM_Frontend_Environment $environment, $userInput) { $value = parent::validate($environment, $userInput); $value = CM_Params::jsonDecode($value); $location = CM_Model_Location::fromArray($value); if ($location->getLevel() < $this->_options['levelMin'] || $location->getLevel() > $this->_options['levelMax']) { throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Invalid location level.')); } return $location; }
public function testProcessReturnDeployVersion() { $body = CM_Params::jsonEncode(['method' => 'CM_Http_Response_RPCTest.add', 'params' => [2, 3]]); $site = $this->getMockSite(); $request = new CM_Http_Request_Post('/rpc', null, null, $body); $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager()); $response->process(); $responseDecoded = CM_Params::jsonDecode($response->getContent()); $this->assertArrayHasKey('deployVersion', $responseDecoded); $this->assertSame(CM_App::getInstance()->getDeployVersion(), $responseDecoded['deployVersion']); }
public function testLoadPageRedirectLanguage() { $site = CM_Site_Abstract::factory(); CMTest_TH::createLanguage('en'); $viewer = CMTest_TH::createUser(); $environment = new CM_Frontend_Environment(null, $viewer); $component = new CM_Page_View_Ajax_Test_Mock(); $response = $this->getResponseAjax($component, 'loadPage', ['path' => '/en' . CM_Page_View_Ajax_Test_Mock::getPath()], $environment); $this->assertViewResponseSuccess($response); $responseDecoded = CM_Params::jsonDecode($response->getContent()); $this->assertSame($site->getUrl() . CM_Page_View_Ajax_Test_Mock::getPath(), $responseDecoded['success']['data']['url']); }
protected function _load() { $data = []; $file = $this->_getStorageFile(); if ($file->exists()) { $values = (array) CM_Params::jsonDecode($file->read()); $data = \Functional\map($values, function ($timeStamp) { return new DateTime('@' . $timeStamp); }); } return $data; }
public function load(CM_OutputStream_Interface $output) { $mongoClient = $this->getServiceManager()->getMongoDb(); foreach (CM_Util::getResourceFiles('mongo/collections.json') as $dump) { $collectionInfo = CM_Params::jsonDecode($dump->read()); foreach ($collectionInfo as $collection => $indexes) { $mongoClient->createCollection($collection); foreach ($indexes as $indexInfo) { $mongoClient->createIndex($collection, $indexInfo['key'], $indexInfo['options']); } } } }
/** * @param string $email * @return array|null */ protected function _getResponseBody($email) { try { $response = $this->_getResponse($email); try { $body = CM_Params::jsonDecode($response->getBody()); } catch (CM_Exception_Invalid $exception) { $body = null; } $responseCode = isset($body['email']['responsecode']) ? (int) $body['email']['responsecode'] : null; $responseCodeInvalidList = array(503 => 'Invalid API Key/Service Not Active'); if (null === $responseCode || isset($responseCodeInvalidList[$responseCode])) { throw new CM_Exception('Invalid XVerify email validation response', array('email' => $email, 'code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody())); } } catch (Exception $exception) { $this->_logException($exception); return null; } return $body['email']; }
/** * @param string $serverKey * @param string $sessionData * @param string $channelKey * @param string $channelMediaId * @param string $channelData * @param string $streamKey * @param int $streamStart * @throws CM_Exception_AuthFailed * @throws CM_Exception_AuthRequired * @throws CM_Exception_Invalid * @throws CM_Exception_NotAllowed */ public static function rpc_subscribe($serverKey, $sessionData, $channelKey, $channelMediaId, $channelData, $streamKey, $streamStart) { $janus = CM_Service_Manager::getInstance()->getJanus('janus'); self::_authenticate($janus, $serverKey); $server = $janus->getServerList()->findByKey($serverKey); $sessionParams = CM_Params::factory(CM_Params::jsonDecode($sessionData), true); $session = $sessionParams->getSession('sessionId'); $user = $session->getUser(true); $channelKey = (string) $channelKey; $channelMediaId = (string) $channelMediaId; $channelParams = CM_Params::factory(CM_Params::jsonDecode($channelData), true); $channelType = $channelParams->getInt('streamChannelType'); $streamKey = (string) $streamKey; $streamStart = (int) $streamStart; $streamRepository = $janus->getStreamRepository(); /** @var CM_Model_StreamChannel_Media $streamChannel */ $streamChannel = $streamRepository->findStreamChannelByKey($channelKey); if (null === $streamChannel) { $streamChannel = $streamRepository->createStreamChannel($channelKey, $channelType, $server->getId(), $channelMediaId); } else { $channelServerData = ['type' => $streamChannel->getType(), 'mediaId' => $streamChannel->getMediaId(), 'serverId' => $streamChannel->getServerId()]; $channelRequestData = ['type' => $channelType, 'mediaId' => $channelMediaId, 'serverId' => $server->getId()]; if ($channelServerData !== $channelRequestData) { throw new CM_Exception_Invalid('Channel request data differs from server data', null, ['channelRequestData' => $channelRequestData, 'channelServerData' => $channelServerData]); } } try { $streamRepository->createStreamSubscribe($streamChannel, $user, $streamKey, $streamStart); } catch (CM_Exception_NotAllowed $exception) { if (!$streamChannel->hasStreams()) { $streamChannel->delete(); } throw new CM_Exception_NotAllowed('Cannot subscribe', $exception->getSeverity(), ['originalExceptionMessage' => $exception->getMessage()]); } catch (CM_Exception_Invalid $exception) { if (!$streamChannel->hasStreams()) { $streamChannel->delete(); } throw new CM_Exception_Invalid('Cannot subscribe', $exception->getSeverity(), ['originalExceptionMessage' => $exception->getMessage()]); } }
/** * @return array[] * @throws CM_Exception */ private static function _readEmoticonData() { /** @var CM_File[] $configurationFiles */ $configurationFiles = []; /** @var CM_File[] $imageFiles */ $imageFiles = []; $bootloader = CM_Bootloader::getInstance(); foreach ($bootloader->getModules() as $namespace) { $emoticonDir = new CM_File(CM_Util::getModulePath($namespace) . 'layout/default/resource/img/emoticon/'); foreach ($emoticonDir->listFiles(true) as $file) { $name = strtolower($file->getFileNameWithoutExtension()); if ('json' === $file->getExtension()) { $configurationFiles[$name] = $file; } else { $imageFiles[$name] = $file; } } } $dataList = []; $codeList = []; foreach ($imageFiles as $name => $file) { $dataList[$name] = ['name' => $name, 'fileName' => $file->getFileName(), 'codes' => [":{$name}:"]]; $codeList[":{$name}:"] = $name; } foreach ($configurationFiles as $name => $file) { $additionalCodes = CM_Params::jsonDecode($file->read())['additionalCodes']; foreach ($additionalCodes as $code) { if (!array_key_exists($code, $codeList)) { $codeList[$code] = $name; $dataList[$name]['codes'][] = $code; } else { throw new CM_Exception('Emoticon codes overlap', null, ['overlapping emoticons' => [$name, $codeList[$code]], 'code' => $code]); } } } return $dataList; }
public function testLoadPageRedirectLanguage() { $site = $this->getMockSite(null, null, ['url' => 'http://my-site.com']); CMTest_TH::createLanguage('en'); $viewer = CMTest_TH::createUser(); $page = new CM_Page_View_Ajax_Test_Mock(); $env = new CM_Frontend_Environment($site, $viewer); $params = ['path' => '/en' . $page::getPath(), 'currentLayout' => $page->getLayout($env)]; $request = $this->createRequestAjax($page, 'loadPage', $params, null, null, $site); $request->mockMethod('getViewer')->set($viewer); /** @var CM_Http_Response_View_Abstract $response */ $response = $this->processRequest($request); $this->assertViewResponseSuccess($response); $responseDecoded = CM_Params::jsonDecode($response->getContent()); $this->assertSame($site->getUrl() . CM_Page_View_Ajax_Test_Mock::getPath(), $responseDecoded['success']['data']['url']); }
/** * @param mixed $value * @return bool */ protected function _isModel($value) { // Hack proposed by Reto Kaiser in order to support multi-ids if (substr($value, 0, 1) === '{') { $value = CM_Params::jsonDecode($value); } if (is_array($value)) { if (!array_key_exists('id', $value)) { return false; } $value = $value['id']; } return $this->_isInt($value) || $this->_isString($value); }
/** * @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()); } }
/** * @param CM_Janus_Server $server * @return array * @throws CM_Exception_Invalid */ public function fetchStatus(CM_Janus_Server $server) { $encodedStatus = $this->_request('GET', $server, '/status'); return CM_Params::jsonDecode($encodedStatus); }
/** * @param mixed $value * @return bool */ protected function _isModel($value) { if ($this->_isJson($value)) { $value = CM_Params::jsonDecode($value); } if (is_array($value)) { if (!array_key_exists('id', $value)) { return false; } $value = $value['id']; } return $this->_isInt($value) || $this->_isString($value); }
/** * @param GearmanJob $job * @return string|null * @throws CM_Exception_Nonexistent */ public function __executeGearman(GearmanJob $job) { $workload = $job->workload(); try { $params = CM_Params::factory(CM_Params::jsonDecode($workload), true); } catch (CM_Exception_Nonexistent $ex) { throw new CM_Exception_Nonexistent('Cannot decode workload for Job `' . get_class($this) . '`: Original exception message `' . $ex->getMessage() . '`', CM_Exception::WARN); } return CM_Params::encode($this->_executeJob($params), true); }
/** * @return array */ protected function _fetchStatus() { $statusData = array(); foreach ($this->_servers as $server) { $statusData = array_merge_recursive($statusData, CM_Params::jsonDecode(CM_Util::getContents('http://' . $server['httpHost'] . ':' . $server['httpPort']))); } return $statusData; }