Ejemplo n.º 1
0
 /**
  * Set the function body
  * @uses WsdlToPhpModel::getName()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::nameIsClean()
  * @uses WsdlToPhpModel::cleanString()
  * @uses WsdlToPhpModel::uniqueName()
  * @uses WsdlToPhpFunction::getParameterType()
  * @uses WsdlToPhpFunction::getOwner()
  * @uses WsdlToPhpFunction::getMethodName()
  * @uses WsdlToPhpStruct::getAttributes()
  * @uses WsdlToPhpStruct::getIsStruct()
  * @uses WsdlToPhpStructAttribute::getGetterName()
  * @uses WsdlToPhpGenerator::getOptionResponseAsWsdlObject()
  * @uses WsdlToPhpGenerator::getOptionSendParametersAsArray()
  * @uses WsdlToPhpGenerator::getOptionSendArrayAsParameter()
  * @uses WsdlToPhpGenerator::getOptionSendArrayAsParameter()
  * @param array
  * @return void
  */
 public function getBody(&$_body)
 {
     $parameterModel = self::getModelByName($this->getParameterType());
     $parameterModel = $parameterModel && $parameterModel->getIsStruct() && !$parameterModel->getIsRestriction() ? $parameterModel : null;
     $returnModel = self::getModelByName($this->getReturnType());
     $returnModel = $returnModel && $returnModel->getIsStruct() && !$returnModel->getIsRestriction() ? $returnModel : null;
     if ($parameterModel) {
         if (count($parameterModel->getAttributes(true, true))) {
             $parameterName = '$_' . lcfirst($parameterModel->getPackagedName());
             $parameter = $parameterModel->getPackagedName() . ' ' . $parameterName;
         } else {
             $parameterName = $parameter = '';
         }
     } elseif (is_string($this->getParameterType())) {
         $parameterName = $parameter = '$_' . lcfirst(self::cleanString($this->getParameterType()));
     } elseif (is_array($this->getParameterType())) {
         $parameters = array();
         foreach ($this->getParameterType() as $parameterName => $parameterType) {
             $model = self::getModelByName($parameterType);
             if (false && $model && $model->getIsStruct() && !$model->getIsRestriction()) {
                 $parameterName = $model->getPackagedName();
             } else {
                 $parameterName = self::cleanString($parameterName);
             }
             array_push($parameters, ($model && $model->getIsStruct() && !$model->getIsRestriction() ? $model->getPackagedName() . ' ' : '') . '$_' . lcfirst($parameterName));
         }
         $parameterName = $parameter = implode(',', $parameters);
     } else {
         $parameterName = $parameter = '';
     }
     array_push($_body, 'public function ' . $this->getMethodName() . '(' . $parameter . ')');
     array_push($_body, '{');
     array_push($_body, 'try');
     array_push($_body, '{');
     /**
      * Response
      */
     $responseAsObjStart = WsdlToPhpGenerator::getOptionResponseAsWsdlObject() && $returnModel ? 'new ' . $returnModel->getPackagedName() . '(' : '';
     $responseAsObjEnd = WsdlToPhpGenerator::getOptionResponseAsWsdlObject() && $returnModel ? ')' : '';
     /**
      * Soap parameters
      */
     if ($parameterModel) {
         $attributes = $parameterModel->getAttributes(true, true);
         if (count($attributes)) {
             $soapParametersStart = $parameterName;
             $soapParametersEnd = '';
         } else {
             $soapParametersStart = $soapParametersEnd = '';
         }
     } elseif (is_string($this->getParameterType())) {
         $soapParametersStart = WsdlToPhpGenerator::getOptionSendArrayAsParameter() ? '\'' . addslashes($this->getParameterType()) . '\'=>' : '';
         $soapParametersEnd = '$_' . lcfirst(self::cleanString($this->getParameterType()));
     } elseif (is_array($this->getParameterType())) {
         $soapParametersStart = array();
         $soapParametersEnd = '';
         foreach ($this->getParameterType() as $parameterName => $parameterType) {
             $model = self::getModelByName($parameterType);
             if (false && $model && $model->getIsStruct() && !$model->getIsRestriction()) {
                 $paramName = $model->getPackagedName();
             } else {
                 $paramName = self::cleanString($parameterName);
             }
             array_push($soapParametersStart, (WsdlToPhpGenerator::getOptionSendArrayAsParameter() ? '\'' . addslashes($parameterName) . '\'=>' : '') . '$_' . lcfirst($paramName));
             unset($model);
         }
         $soapParametersStart = implode(',', $soapParametersStart);
     } else {
         $soapParametersStart = $soapParametersEnd = '';
     }
     /**
      * Soap call
      */
     $soapCallStart = 'self::getSoapClient()->' . ($this->nameIsClean() ? $this->getName() . '(' : '__soapCall(\'' . $this->getName() . '\'' . (!empty($soapParametersStart) || !empty($soapParametersEnd) ? ',array(' : ''));
     $soapCallEnd = (!$this->nameIsClean() && (!empty($soapParametersStart) || !empty($soapParametersEnd)) ? ')' : '') . ')' . (WsdlToPhpGenerator::getOptionSendParametersAsArray() ? '->parameters' : '');
     /**
      * Send parameters in parameters array
      */
     if (!empty($soapParametersStart) && $this->nameIsClean()) {
         $sendParametersAsArrayStart = WsdlToPhpGenerator::getOptionSendParametersAsArray() ? 'array(\'parameters\'=>' : '';
         $sendParametersAsArrayEnd = WsdlToPhpGenerator::getOptionSendParametersAsArray() ? ')' : '';
     } else {
         $sendParametersAsArrayStart = $sendParametersAsArrayEnd = '';
     }
     /**
      * Send an array
      */
     if (!empty($soapParametersStart) && $this->nameIsClean()) {
         $sendArrayAsParameterStart = WsdlToPhpGenerator::getOptionSendArrayAsParameter() ? 'array(' : '';
         $sendArrayAsParameterEnd = WsdlToPhpGenerator::getOptionSendArrayAsParameter() ? ')' : '';
     } else {
         $sendArrayAsParameterStart = $sendArrayAsParameterEnd = '';
     }
     array_push($_body, 'return $this->setResult(' . $responseAsObjStart . $soapCallStart . $sendParametersAsArrayStart . $sendArrayAsParameterStart . $soapParametersStart . $soapParametersEnd . $sendArrayAsParameterEnd . $sendParametersAsArrayEnd . $soapCallEnd . $responseAsObjEnd . ');');
     array_push($_body, '}');
     array_push($_body, 'catch(SoapFault $soapFault)');
     array_push($_body, '{');
     array_push($_body, 'return !$this->saveLastError(__METHOD__,$soapFault);');
     array_push($_body, '}');
     array_push($_body, '}');
     unset($parameterModel, $parameter, $responseAsObjStart, $responseAsObjEnd, $soapCallStart, $soapCallEnd, $sendParametersAsArrayStart, $sendParametersAsArrayEnd, $sendParametersAsArrayStart, $sendArrayAsParameterEnd, $soapParametersStart, $soapParametersEnd);
 }