Gpf_Rpc_Request::addParam PHP Method

addParam() public method

public addParam ( $name, $value )
        public function addParam($name, $value)
        {
            if (is_scalar($value) || is_null($value)) {
                $this->params->add($name, $value);
                return;
            }
            if ($value instanceof Gpf_Rpc_Serializable) {
                $this->params->add($name, $value->toObject());
                return;
            }
            throw new Gpf_Exception("Cannot add request param: Value ({$name}={$value}) is not scalar or Gpf_Rpc_Serializable");
        }

Usage Example

示例#1
0
 public function send()
 {
     $request = new Gpf_Rpc_Request($this->serverClassName, Gpf_Rpc_Server::RUN_METHOD);
     $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);
     }
 }