public static function render() { $encoder = new Gpf_Rpc_Json(); $out = ''; $response = self::getInstance(); foreach ($response->encodedResponses as $id => $value) { $out .= 'window["' . $id . '"]="' . $value . '";'; } foreach ($response->responses as $id => $value) { $out .= 'window["' . $id . '"]="' . addcslashes($encoder->encodeResponse($value), '"\\') . '";'; } return '<script type="text/javascript">' . $out . '</script>'; }
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 addAvailableValue($value, $label) { $record = $this->availableValues->createRecord(); $record->set('id', $value); $record->set('name', $label); $this->availableValues->addRecord($record); $json = new Gpf_Rpc_Json(); $this->setAvailableValues($json->encodeResponse($this->availableValues)); }
/** * @return string string representation of input var or an error if a problem occurs */ public function encodeResponse(Gpf_Rpc_Serializable $response) { return '<html><script type="text/javascript"> window.name="' . addcslashes(parent::encodeResponse($response), '"\\') . '";</script></html>'; }
private function exportClientCacheFile($dirName) { $file = new Gpf_Io_File($this->getCacheFileName($dirName, false)); $file->setFileMode('w'); if (!$file->isExists()) { $file->setFilePermissions(0777); } $recordSet = new Gpf_Data_RecordSet(); $recordSet->setHeader(array('source', 'translation')); foreach ($this->translations as $translation) { if ($translation->getType() == Gpf_Lang_Parser_Translation::TYPE_CLIENT || $translation->getType() == Gpf_Lang_Parser_Translation::TYPE_BOTH) { if ($translation->getStatus() != 'D') { $recordSet->add(array($translation->getSourceMessage(), $translation->getDestinationMessage())); } } } $recordSet->add(array("_dateFormat", $this->getMetaValue(self::LANG_DATE_FORMAT))); $recordSet->add(array("_timeFormat", $this->getMetaValue(self::LANG_TIME_FORMAT))); $recordSet->add(array("_thousandsSeparator", $this->getMetaValue(self::LANG_THOUSANDS_SEPARATOR))); $recordSet->add(array("_decimalSeparator", $this->getMetaValue(self::LANG_DECIMAL_SEPARATOR))); $encoder = new Gpf_Rpc_Json(); $file->write(addcslashes($encoder->encodeResponse($recordSet), '"\\')); $file->close(); }