decodes a JSON string into appropriate variable
public decode ( string $str ) : mixed | ||
$str | string | JSON-formatted string |
return | mixed | number, boolean, string, array, or object corresponding to given JSON input string. See argument 1 to Services_JSON() above for object-output behavior. Note that decode() always returns strings in ASCII or UTF-8 format! |
protected function execute() { $json = new Gpf_Rpc_Json(); $processor = new Pap_Features_CompressedCommissionPlacementModel_Processor(); if ($this->isPending('initAffiliatesList', $this->_('Initialization affiliates list'))) { $this->debug('initAffiliatesList'); $this->userIds = $processor->initAffiliates(); $this->setParams($json->encode($this->userIds)); $this->setDone(); } if ($this->isPending('initTransactionsList', $this->_('Initialization transactions list'))) { $this->debug('initTransactionsList'); $this->userIds = $json->decode($this->getParams()); $this->affectedTransactions = $processor->initTransactions($this->userIds); $this->setParams($json->encode($this->getTransactionIdsFromCollection($this->affectedTransactions))); $this->setDone(); } $affectedTransactionIds = $this->getCollectionFromIds($json->decode($this->getParams())); $this->debug('process transactions'); while ($affectedTransactionIds->getSize() > 0) { if ($this->isPending($this->getFirstElement($affectedTransactionIds)->getId(), $this->_('Compressed transaction: %s', $this->getFirstElement($affectedTransactionIds)->getId()))) { $processor->processFirstTransaction($affectedTransactionIds); $this->setDone(); } else { $processor->removeByTransactionId($this->getFirstElement($affectedTransactionIds)->getId(), $affectedTransactionIds); } } $this->debug('finish task'); $this->forceFinishTask(); }
private function removeMapOverlayFromAffiliatePanel() { $affMenu = Gpf_Settings::get(Pap_Settings::AFFILIATE_MENU); $json = new Gpf_Rpc_Json(); $affMenuDecoded = $json->decode($affMenu); try { $affMenuDecoded = $this->removeMenuItem($affMenuDecoded, $this->getMapOverlayScreenId()); Gpf_Settings::set(Pap_Settings::AFFILIATE_MENU,$json->encode($affMenuDecoded)); } catch (Gpf_DbEngine_NoRowException $e) { } }
protected function getRequestIdsIterator() { $json = new Gpf_Rpc_Json(); $requestParams = new Gpf_Rpc_Params($json->decode($this->params->get(self::IDS_REQUEST))); $c = $requestParams->getClass(); $gridService = new $c(); if (!$gridService instanceof Gpf_View_GridService) { throw new Gpf_Exception(sprintf('%s is not Gpf_View_GridService class.', $requestParams->getClass())); } return $gridService->getIdsIterator($requestParams); }
public function decode($string) { if ($string == null || $string == "") { throw new Gpf_Exception("Invalid format (" . get_class($this) . ")"); } $string = stripslashes($string); $json = new Gpf_Rpc_Json(); $object = $json->decode($string); if (!is_object($object)) { throw new Gpf_Exception("Invalid format (" . get_class($this) . ")"); } $this->initFrom($object); }
public function getMPTTArray() { if ($this->jsonString == null) { throw new Gpf_Exception('No JSON string was set! There are no data to create mptt tree structure'); } $json = new Gpf_Rpc_Json(); $tree = $json->decode($this->jsonString); if (count($tree) > 0) { $this->parseTree($tree, 2); } $this->mpttArray[] = array("lft" => 1, "rgt" => count($this->mpttArray) * 2 + 2, 'name' => 'root', 'state' => '', 'code' => '0'); return $this->mpttArray; }
private function loadActions($actionsString) { if ($actionsString == '') { throw new Gpf_Exception($this->_('no actions in visit')); } $actionsArray = $this->json->decode($actionsString); if (!is_array($actionsArray)) { throw new Gpf_Exception($this->_('invalid action format (%s)', $actionsString)); } $actions = array(); foreach ($actionsArray as $actionObject) { $actions[] = new Pap_Tracking_Action_RequestActionObject($actionObject); } return $actions; }
public function execute() { $tree = Gpf_Settings::get(Pap_Settings::AFFILIATE_MENU); if (strpos($tree, '"data":{"code":')) { return; } $json = new Gpf_Rpc_Json(); $tree = $json->decode($tree); $this->changeItem($tree); Gpf_Settings::set(Pap_Settings::AFFILIATE_MENU,$json->encode($tree)); }
public function send() { $request = new Gpf_Rpc_Request($this->serverClassName, Gpf_Rpc_Server::RUN_METHOD); if ($this->useNewStyleRequestsEncoding) { $request->addParam(Gpf_Rpc_Server::REQUESTS_SHORT, $this->requests); } else { $request->addParam(Gpf_Rpc_Server::REQUESTS, $this->requests); } if ($this->sessionId != null) { $request->addParam("S", $this->sessionId); } $requestBody = $this->json->encodeResponse($request); $responseText = $this->sendRequest($requestBody); if ($this->debugRequests) { echo "REQUEST: " . $requestBody . "<br/>"; echo "RESPONSE: " . $responseText . "<br/><br/>"; } $responseArray = $this->json->decode($responseText); if (!is_array($responseArray)) { throw new Gpf_Exception("Response decoding failed: not array. Received text: {$responseText}"); } if (count($responseArray) != $this->requests->getCount()) { throw new Gpf_Exception("Response decoding failed: Number of responses is not same as number of requests"); } $exception = false; foreach ($responseArray as $index => $response) { if (is_object($response) && isset($response->e)) { $exception = true; $this->requests->get($index)->setResponseError($response->e); } else { $this->requests->get($index)->setResponse($response); } } if ($exception) { $messages = ''; foreach ($this->requests as $request) { $messages .= $request->getResponseError() . "|"; } } $this->requests = new Gpf_Rpc_Array(); if ($exception) { throw new Gpf_Rpc_ExecutionException($messages); } }
public function __construct($request) { $json = new Gpf_Rpc_Json(); $this->params = new Gpf_Rpc_Params($json->decode($request)); parent::__construct($this->params); }
protected function loadFromTask() { parent::loadFromTask(); $json = new Gpf_Rpc_Json(); $values = $json->decode($this->getParams()); $this->paramsArray['papUserIds'] = $values->papUserIds; }
private function addPostParams(Gpf_Rpc_Params $params) { if ($params->exists('fields')) { $json = new Gpf_Rpc_Json(); foreach ($params->get('fields') as $field) { if (!$params->exists($field[0])) { $decodedItem = $json->decode($field[1]); if ($decodedItem !== null || $decodedItem != '') { $params->add($field[0], $decodedItem); } else { $params->add($field[0], $field[1]); } } } } }
protected function loadFromTask() { parent::loadFromTask(); $json = new Gpf_Rpc_Json(); $values = $json->decode($this->getParams()); if (isset($values->isPending)) { $this->paramsArray['isPending'] = $values->isPending; if (isset($values->importedLinesCount)) { $this->paramsArray['importedLinesCount'] = $values->importedLinesCount; } else { $this->paramsArray['importedLinesCount'] = 0; } if (isset($values->importedLinesCount)) { $this->paramsArray['wrongLinesCount'] = $values->wrongLinesCount; } else { $this->paramsArray['wrongLinesCount'] = 0; } } }
/** * @return array */ private function getDecodedParams() { try { $json = new Gpf_Rpc_Json(); $encodedParams = $this->getParams(); $stdObject = $json->decode($encodedParams); if($stdObject){ $decodedParams = get_object_vars($stdObject); if ($decodedParams) return $decodedParams; } } catch (Exception $e) { } return array(); }