本文整理汇总了PHP中CM_Params::jsonDecode方法的典型用法代码示例。如果您正苦于以下问题:PHP CM_Params::jsonDecode方法的具体用法?PHP CM_Params::jsonDecode怎么用?PHP CM_Params::jsonDecode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CM_Params
的用法示例。
在下文中一共展示了CM_Params::jsonDecode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getVariables
/**
* @return string[]
*/
public function getVariables()
{
if (!$this->_has('variables')) {
return array();
}
$variablesEncoded = $this->_get('variables');
return CM_Params::jsonDecode($variablesEncoded);
}
示例2: testProcessingInvalidMethod
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);
}
示例3: validate
/**
* @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;
}
示例4: testProcessReturnDeployVersion
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']);
}
示例5: testLoadPageRedirectLanguage
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']);
}
示例6: _load
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;
}
示例7: load
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']);
}
}
}
}
示例8: _getResponseBody
/**
* @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'];
}
示例9: rpc_subscribe
/**
* @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()]);
}
}
示例10: _readEmoticonData
/**
* @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;
}
示例11: testLoadPageRedirectLanguage
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']);
}
示例12: _isModel
/**
* @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);
}
示例13: subscribe
/**
* @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());
}
}
示例14: fetchStatus
/**
* @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);
}
示例15: _isModel
/**
* @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);
}