Пример #1
0
 /**
  * Returns the comment lines for this service
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getGenericWsdlClassName()
  * @uses WsdlToPhpModel::getMetaValue()
  * @uses WsdlToPhpModel::cleanString()
  * @uses WsdlToPhpStruct::getContextualPart()
  * @uses WsdlToPhpService::getFunctions()
  * @uses WsdlToPhpFunction::getReturnType()
  * @uses WsdlToPhpFunction::getComment()
  * @uses WsdlToPhpFunction::getBody()
  * @uses WsdlToPhpGenerator::getPackageName()
  * @uses WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()
  * @param array $_body
  * @return void
  */
 public function getClassBody(&$_body)
 {
     if (count($this->getFunctions())) {
         $returnTypes = array();
         $soapHeaders = array();
         /**
          * Gather informations
          */
         foreach ($this->getFunctions() as $function) {
             /**
              * Gather return types
              */
             $model = self::getModelByName($function->getReturnType());
             if ($model && $model->getIsStruct()) {
                 array_push($returnTypes, $model->getPackagedName());
                 unset($model);
             } else {
                 array_push($returnTypes, $function->getReturnType());
             }
             /**
              * Gather SoapHeader informations
              */
             $soapHeaderNames = $function->getMetaValue('SOAPHeaderNames', array());
             $soapHeaderTypes = $function->getMetaValue('SOAPHeaderTypes', array());
             $soapHeaderNameSpaces = $function->getMetaValue('SOAPHeaderNamespaces', '');
             if (count($soapHeaderNames) && count($soapHeaderNames) == count($soapHeaderTypes)) {
                 foreach ($soapHeaderNames as $index => $soapHeaderName) {
                     $soapHeaderType = str_replace('{@link ', '', $soapHeaderTypes[$index]);
                     $soapHeaderType = str_replace('}', '', $soapHeaderType);
                     $soapHeaderKey = $soapHeaderName . '-' . $soapHeaderType;
                     if (!array_key_exists($soapHeaderKey, $soapHeaders)) {
                         $soapHeaders[$soapHeaderKey] = array('name' => $soapHeaderName, 'type' => $soapHeaderType, 'namespaces' => array($soapHeaderNameSpaces[$index]));
                     } elseif (!in_array($soapHeaderNameSpaces[$index], $soapHeaders[$soapHeaderKey]['namespaces'])) {
                         array_push($soapHeaders[$soapHeaderKey]['namespaces'], $soapHeaderNameSpaces[$index]);
                     }
                 }
             }
         }
         /**
          * Generates the SoapHeaders setter methods
          */
         if (count($soapHeaders) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
             $whateverStruct = new WsdlToPhpStruct('whatever');
             $soapHeaderNameUniqueMethods = array();
             foreach ($soapHeaders as $soapHeader) {
                 $soapHeaderName = $soapHeader['name'];
                 $soapHeaderType = $soapHeader['type'];
                 $soapHeaderNameSpaces = $soapHeader['namespaces'];
                 $cleanedName = $this->cleanString($soapHeaderName, false);
                 $headerParamKnown = strpos($soapHeaderType, WsdlToPhpGenerator::getPackageName() . $whateverStruct->getContextualPart()) === 0;
                 $methodName = ucfirst($cleanedName);
                 /**
                  * Ensure unique setter naming
                  */
                 if (!array_key_exists($methodName, $soapHeaderNameUniqueMethods)) {
                     $soapHeaderNameUniqueMethods[$methodName] = 0;
                 } else {
                     $soapHeaderNameUniqueMethods[$methodName]++;
                 }
                 $methodName .= $soapHeaderNameUniqueMethods[$methodName] ? '_' . $soapHeaderNameUniqueMethods[$methodName] : '';
                 /**
                  * setSoapHeader() method comments
                  */
                 $comments = array();
                 array_push($comments, 'Sets the ' . $soapHeaderName . ' SoapHeader param');
                 array_push($comments, '@uses ' . self::getGenericWsdlClassName() . '::setSoapHeader()');
                 array_push($comments, '@param ' . $soapHeaderType . ' $_' . lcfirst($headerParamKnown ? $soapHeaderType : $cleanedName));
                 array_push($comments, '@param string $_nameSpace ' . implode(', ', $soapHeaderNameSpaces));
                 array_push($comments, '@param bool $_mustUnderstand');
                 array_push($comments, '@param string $_actor');
                 array_push($comments, '@return bool true|false');
                 /**
                  * getResult() method body
                  */
                 array_push($_body, array('comment' => $comments));
                 array_push($_body, 'public function setSoapHeader' . $methodName . '(' . ($headerParamKnown ? $soapHeaderType . ' ' : '') . '$_' . lcfirst($headerParamKnown ? $soapHeaderType : $cleanedName) . ',$_nameSpace' . (count($soapHeaderNameSpaces) > 1 ? '' : ' = ' . var_export($soapHeaderNameSpaces[0], true)) . ',$_mustUnderstand = false,$_actor = null)');
                 array_push($_body, '{');
                 array_push($_body, 'return $this->setSoapHeader($_nameSpace,\'' . $soapHeaderName . '\',$_' . lcfirst($headerParamKnown ? $soapHeaderType : $cleanedName) . ',$_mustUnderstand,$_actor);');
                 array_push($_body, '}');
                 unset($soapHeaderName, $soapHeaderType, $soapHeaderNameSpaces, $cleanedName, $headerParamKnown, $methodName, $comments);
             }
         }
         /**
          * Generates service methods
          */
         foreach ($this->getFunctions() as $function) {
             array_push($_body, array('comment' => $function->getComment()));
             $function->getBody($_body);
         }
         /**
          * Generates the override getResult method if needed
          */
         if (count($returnTypes) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
             $returnTypes = array_unique($returnTypes);
             natcasesort($returnTypes);
             /**
              * getResult() method comments
              */
             $comments = array();
             array_push($comments, 'Returns the result');
             array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::getResult()');
             array_push($comments, '@return ' . implode('|', $returnTypes));
             /**
              * getResult() method body
              */
             array_push($_body, array('comment' => $comments));
             array_push($_body, 'public function getResult()');
             array_push($_body, '{');
             array_push($_body, 'return parent::getResult();');
             array_push($_body, '}');
             unset($comments);
         }
         unset($returnTypes, $soapHeaders);
     }
 }
 /**
  * Returns the array of lines to declare the setter
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::getCleanName()
  * @uses WsdlToPhpModel::nameIsClean()
  * @uses WsdlToPhpModel::getName()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getInheritance()
  * @uses WsdlToPhpStruct::getIsRestriction()
  * @uses WsdlToPhpStruct::isArray()
  * @uses WsdlToPhpStructAttribute::getType()
  * @uses WsdlToPhpStructAttribute::getSetterName()
  * @uses WsdlToPhpStructAttribute::getOwner()
  * @param array $_body
  * @param WsdlToPhpStruct $_struct
  * @return void
  */
 public function getSetterDeclaration(&$_body, WsdlToPhpStruct $_struct)
 {
     $model = self::getModelByName($this->getType());
     /**
      * set() method comment
      */
     $comments = array();
     array_push($comments, 'Set ' . $this->getName() . ' value');
     if ($model && $model->getIsRestriction() && !$_struct->isArray()) {
         array_push($comments, '@uses ' . $model->getPackagedName() . '::valueIsValid()');
     }
     if ($model) {
         if ($model->getIsStruct() && $model->getPackagedName() != $this->getOwner()->getPackagedName()) {
             array_push($comments, '@param ' . $model->getPackagedName() . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
             array_push($comments, '@return ' . $model->getPackagedName());
         } else {
             array_push($comments, '@param ' . ($model->getInheritance() ? $model->getInheritance() : $this->getType()) . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
             array_push($comments, '@return ' . ($model->getInheritance() ? $model->getInheritance() : $this->getType()));
         }
     } else {
         array_push($comments, '@param ' . $this->getType() . ' $_' . lcfirst($this->getCleanName()) . ' the ' . $this->getName());
         array_push($comments, '@return ' . $this->getType());
     }
     array_push($_body, array('comment' => $comments));
     /**
      * set() method body
      */
     array_push($_body, 'public function ' . $this->getSetterName() . '($_' . lcfirst($this->getCleanName()) . ')');
     array_push($_body, '{');
     if ($model && $model->getIsRestriction() && !$_struct->isArray()) {
         array_push($_body, 'if(!' . $model->getPackagedName() . '::valueIsValid($_' . lcfirst($this->getCleanName()) . '))');
         array_push($_body, '{');
         array_push($_body, 'return false;');
         array_push($_body, '}');
     }
     if ($this->nameIsClean()) {
         array_push($_body, 'return ($this->' . $this->getName() . ' = $_' . lcfirst($this->getCleanName()) . ');');
     } else {
         array_push($_body, 'return ($this->' . $this->getCleanName() . ' = $this->{\'' . addslashes($this->getName()) . '\'} = $_' . lcfirst($this->getCleanName()) . ');');
     }
     array_push($_body, '}');
     unset($model, $comments);
 }