Пример #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);
     }
 }
Пример #2
0
 /**
  * Method to override in sub class
  * Must return a string in order to declare the function, attribute or the value
  * @uses WsdlToPhpStruct::getIsStruct()
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::getInheritance()
  * @uses WsdlToPhpModel::getComment()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getClassBody()
  * @uses WsdlToPhpModel::getGenericWsdlClassName()
  * @uses WsdlToPhpGenerator::getOptionInheritsClassIdentifier()
  * @uses WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()
  * @return string
  */
 public function getClassDeclaration()
 {
     $class = array();
     /**
      * Class comments
      */
     array_push($class, array('comment' => $this->getFileComment()));
     array_push($class, array('comment' => $this->getClassComment()));
     /**
      * Extends
      */
     $extends = '';
     $base = WsdlToPhpGenerator::getOptionInheritsClassIdentifier();
     if (!empty($base) && ($model = self::getModelByName($this->getName() . $base))) {
         if ($model->getIsStruct()) {
             $extends = $model->getPackagedName();
         }
     } elseif ($this->getInheritance() != '' && ($model = self::getModelByName($this->getInheritance()))) {
         if ($model->getIsStruct()) {
             $extends = $model->getPackagedName();
         }
     } elseif (class_exists($this->getInheritance()) && stripos($this->getInheritance(), WsdlToPhpGenerator::getPackageName()) === 0) {
         $extends = $this->getInheritance();
     }
     if (empty($extends) && WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
         $extends = self::getGenericWsdlClassName();
     }
     array_push($class, ($this->getIsAbstract() ? 'abstract ' : '') . 'class ' . $this->getPackagedName() . (!empty($extends) ? ' extends ' . $extends : ''));
     /**
      * Class body starts here
      */
     array_push($class, '{');
     /**
      * Populate class body
      */
     $this->getClassBody($class);
     /**
      * __toString() method comments
      */
     $comments = array();
     array_push($comments, 'Method returning the class name');
     array_push($comments, '@return string __CLASS__');
     array_push($class, array('comment' => $comments));
     unset($comments);
     /**
      * __toString method body
      */
     array_push($class, 'public function __toString()');
     array_push($class, '{');
     array_push($class, 'return __CLASS__;');
     array_push($class, '}');
     /**
      * Class body ends here
      */
     array_push($class, '}');
     return $class;
 }
Пример #3
0
 /**
  * Returns the comment lines for this function
  * @see WsdlToPhpModel::getComment()
  * @uses WsdlToPhpStructAttribute::getGetterName()
  * @uses WsdlToPhpFunction::getParameterType()
  * @uses WsdlToPhpFunction::getReturnType()
  * @uses WsdlToPhpFunction::getIsUnique()
  * @uses WsdlToPhpStruct::getAttributes()
  * @uses WsdlToPhpStruct::getIsStruct()
  * @uses WsdlToPhpStruct::getIsRestriction()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::addMetaComment()
  * @uses WsdlToPhpModel::getDocumentation()
  * @uses WsdlToPhpModel::getGenericWsdlClassName()
  * @uses WsdlToPhpModel::cleanString()
  * @return array
  */
 public function getComment()
 {
     $comments = array();
     array_push($comments, 'Method to call the operation originally named ' . $this->getName());
     if (!$this->getIsUnique()) {
         array_push($comments, 'This method has been renamed because it is defined several times but with different signature');
     }
     if ($this->getDocumentation() != '') {
         array_push($comments, 'Documentation : ' . $this->getDocumentation());
     }
     $this->addMetaComment($comments, false, true);
     /**
      * @Uses and @Param
      */
     if (WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
         array_push($comments, '@uses ' . self::getGenericWsdlClassName() . '::getSoapClient()');
         array_push($comments, '@uses ' . self::getGenericWsdlClassName() . '::setResult()');
         array_push($comments, '@uses ' . self::getGenericWsdlClassName() . '::saveLastError()');
     }
     if (is_string($this->getParameterType())) {
         $model = self::getModelByName($this->getParameterType());
         if ($model && $model->getIsStruct() && !$model->getIsRestriction()) {
             array_push($comments, '@param ' . $model->getPackagedName() . ' $_' . lcfirst($model->getPackagedName()));
         } else {
             array_push($comments, '@param ' . $this->getParameterType() . ' $_' . lcfirst($this->getParameterType()));
         }
     } elseif (is_array($this->getParameterType())) {
         foreach ($this->getParameterType() as $parameterName => $parameterType) {
             $model = self::getModelByName($parameterType);
             if ($model && $model->getIsStruct() && !$model->getIsRestriction()) {
                 array_push($comments, '@param ' . $model->getPackagedName() . ' $_' . lcfirst(self::cleanString($parameterName)));
             } else {
                 array_push($comments, '@param ' . $parameterType . ' $_' . lcfirst(self::cleanString($parameterName)));
             }
         }
     }
     /**
      * @Return
      */
     $model = self::getModelByName($this->getReturnType());
     if ($model && $model->getIsStruct() && !$model->getIsRestriction()) {
         array_push($comments, '@return ' . $model->getPackagedName());
     } else {
         array_push($comments, '@return ' . $this->getReturnType());
     }
     unset($model);
     return $comments;
 }
Пример #4
0
 /**
  * Returns the constructor method
  * @uses WsdlToPhpModel::getName()
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpModel::getCleanName()
  * @uses WsdlToPhpModel::getInheritance()
  * @uses WsdlToPhpModel::getGenericWsdlClassName()
  * @uses WsdlToPhpStruct::isArray()
  * @uses WsdlToPhpStruct::getIsRestriction()
  * @uses WsdlToPhpStruct::getValues()
  * @uses WsdlToPhpStruct::getAttributes()
  * @uses WsdlToPhpStruct::getIsStruct()
  * @uses WsdlToPhpStructValue::getComment()
  * @uses WsdlToPhpStructValue::getDeclaration()
  * @uses WsdlToPhpStructValue::getCleanName()
  * @uses WsdlToPhpStructAttribute::getComment()
  * @uses WsdlToPhpStructAttribute::getDeclaration()
  * @uses WsdlToPhpStructAttribute::isRequired()
  * @uses WsdlToPhpStructAttribute::getType()
  * @uses WsdlToPhpStructAttribute::getDefaultValue()
  * @uses WsdlToPhpStructAttribute::getGetterDeclaration()
  * @uses WsdlToPhpStructAttribute::getSetterDeclaration()
  * @uses WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()
  * @uses WsdlToPhpGenerator::getPackageName()
  * @param array $_body the body which will be populated
  * @return array
  */
 public function getClassBody(&$_body)
 {
     /**
      * A restriction struct with enumeration values
      */
     if ($this->getIsRestriction() && count($this->getValues())) {
         $constantsDefined = array();
         foreach ($this->getValues() as $index => $value) {
             array_push($_body, array('comment' => $value->getComment()));
             array_push($_body, $value->getDeclaration($this->getName(), $index));
             array_push($constantsDefined, $this->getPackagedName() . '::' . $value->getCleanName());
         }
         /**
          * valueIsValid() method comments
          */
         $comments = array();
         array_push($comments, 'Return true if value is allowed');
         foreach ($constantsDefined as $constantName) {
             array_push($comments, '@uses ' . $constantName);
         }
         array_push($comments, '@param mixed $_value value');
         array_push($comments, '@return bool true|false');
         array_push($_body, array('comment' => $comments));
         /**
          * valueIsValid() method body
          */
         array_push($_body, 'public static function valueIsValid($_value)');
         array_push($_body, '{');
         array_push($_body, 'return in_array($_value,array(' . implode(',', $constantsDefined) . '));');
         array_push($_body, '}');
         unset($comments);
     } elseif (count($this->getAttributes())) {
         /**
          * Gathers informations about attributes
          */
         $bodyParameters = array();
         $bodyParams = array();
         $bodyUses = array();
         $constructParameters = array();
         $attributes = $this->getAttributes(false, true);
         foreach ($attributes as $attribute) {
             array_push($_body, array('comment' => $attribute->getComment()));
             array_push($_body, $attribute->getDeclaration());
             array_push($bodyParameters, '$_' . lcfirst($attribute->getCleanName()) . (!$attribute->isRequired() ? ' = ' . var_export($attribute->getDefaultValue(), true) : ''));
             if (!WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
                 array_push($bodyUses, $this->getPackagedName() . '::' . $attribute->getSetterName() . '()');
             }
             $model = self::getModelByName($attribute->getType());
             if ($model) {
                 if ($model->getIsStruct() && $model->getPackagedName() != $this->getPackagedName()) {
                     if ($model->isArray()) {
                         array_push($constructParameters, '\'' . $attribute->getUniqueName() . '\'=>($_' . lcfirst($attribute->getCleanName()) . ' instanceof ' . $model->getPackagedName() . ')?$_' . lcfirst($attribute->getCleanName()) . ':new ' . $model->getPackagedName() . '($_' . lcfirst($attribute->getCleanName()) . ')');
                     } else {
                         array_push($constructParameters, '\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
                     }
                     $paramType = $model->getPackagedName();
                 } else {
                     array_push($constructParameters, '\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
                     $paramType = $model->getInheritance() ? $model->getInheritance() : $attribute->getType();
                 }
             } else {
                 array_push($constructParameters, '\'' . $attribute->getUniqueName() . '\'=>$_' . lcfirst($attribute->getCleanName()));
                 $paramType = $attribute->getType();
             }
             array_push($bodyParams, $paramType . ' $_' . lcfirst($attribute->getCleanName()));
             unset($paramType, $model);
         }
         /**
          * __contruct() method comments
          */
         $comments = array();
         array_push($comments, 'Constructor method for ' . $this->getCleanName());
         /**
          * Uses the parent constructor method
          */
         if (WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
             array_push($comments, '@see parent::__construct()');
         }
         foreach ($bodyUses as $bodyUse) {
             array_push($comments, '@uses ' . $bodyUse);
         }
         foreach ($bodyParams as $bodyParam) {
             array_push($comments, '@param ' . $bodyParam);
         }
         array_push($comments, '@return ' . $this->getPackagedName());
         array_push($_body, array('comment' => $comments));
         /**
          * __contruct() method body
          */
         array_push($_body, 'public function __construct(' . implode(',', $bodyParameters) . ')');
         array_push($_body, '{');
         $model = self::getModelByName($this->getInheritance());
         /**
          * Uses the parent constructor method
          */
         if (WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
             array_push($_body, ($model && $model->getIsStruct() ? self::getGenericWsdlClassName() : 'parent') . '::__construct(array(' . implode(',', $constructParameters) . '),false);');
         } else {
             foreach ($attributes as $attribute) {
                 array_push($_body, '$this->' . $attribute->getSetterName() . '($_' . lcfirst($attribute->getCleanName()) . ');');
             }
         }
         array_push($_body, '}');
         /**
          * Setters and getters
          */
         foreach ($this->getAttributes(false, true) as $attribute) {
             $attribute->getGetterDeclaration($_body, $this);
             $attribute->getSetterDeclaration($_body, $this);
         }
         unset($comments, $bodyParameters, $bodyParams, $constructParameters);
         /**
          * A array struct
          */
         if ($this->isArray()) {
             foreach ($this->getAttributes() as $attr) {
                 $attribute = $attr;
             }
             if ($attribute instanceof WsdlToPhpStructAttribute) {
                 $model = self::getModelByName($attribute->getType());
                 $return = $model && $model->getIsStruct() ? $model->getPackagedName() : $attribute->getType();
                 $comments = array();
                 /**
                  * current() method comments
                  */
                 array_push($comments, 'Returns the current element');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::current()');
                 array_push($comments, '@return ' . $return);
                 array_push($_body, array('comment' => $comments));
                 /**
                  * current() method body
                  */
                 array_push($_body, 'public function current()');
                 array_push($_body, '{');
                 array_push($_body, 'return parent::current();');
                 array_push($_body, '}');
                 $comments = array();
                 /**
                  * item() method comments
                  */
                 array_push($comments, 'Returns the indexed element');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::item()');
                 array_push($comments, '@param int $_index');
                 array_push($comments, '@return ' . $return);
                 array_push($_body, array('comment' => $comments));
                 /**
                  * item() method body
                  */
                 array_push($_body, 'public function item($_index)');
                 array_push($_body, '{');
                 array_push($_body, 'return parent::item($_index);');
                 array_push($_body, '}');
                 $comments = array();
                 /**
                  * first() method comments
                  */
                 array_push($comments, 'Returns the first element');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::first()');
                 array_push($comments, '@return ' . $return);
                 array_push($_body, array('comment' => $comments));
                 /**
                  * first() method body
                  */
                 array_push($_body, 'public function first()');
                 array_push($_body, '{');
                 array_push($_body, 'return parent::first();');
                 array_push($_body, '}');
                 $comments = array();
                 /**
                  * last() method comments
                  */
                 array_push($comments, 'Returns the last element');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::last()');
                 array_push($comments, '@return ' . $return);
                 array_push($_body, array('comment' => $comments));
                 /**
                  * last() method body
                  */
                 array_push($_body, 'public function last()');
                 array_push($_body, '{');
                 array_push($_body, 'return parent::last();');
                 array_push($_body, '}');
                 $comments = array();
                 /**
                  * offsetGet() method comments
                  */
                 array_push($comments, 'Returns the element at the offset');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::last()');
                 array_push($comments, '@param int $_offset');
                 array_push($comments, '@return ' . $return);
                 array_push($_body, array('comment' => $comments));
                 /**
                  * offsetGet() method body
                  */
                 array_push($_body, 'public function offsetGet($_offset)');
                 array_push($_body, '{');
                 array_push($_body, 'return parent::offsetGet($_offset);');
                 array_push($_body, '}');
                 if ($model && $model->getIsRestriction()) {
                     $comments = array();
                     /**
                      * add() method comments
                      */
                     array_push($comments, 'Add element to array');
                     array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::add()');
                     array_push($comments, '@uses ' . $model->getPackagedName() . '::valueIsValid()');
                     array_push($comments, '@param ' . $model->getPackagedName() . ' $_item');
                     array_push($comments, '@return ' . $return);
                     array_push($_body, array('comment' => $comments));
                     /**
                      * add() method body
                      */
                     array_push($_body, 'public function add($_item)');
                     array_push($_body, '{');
                     array_push($_body, 'return ' . $model->getPackagedName() . '::valueIsValid($_item)?parent::add($_item):false;');
                     array_push($_body, '}');
                 }
                 /**
                  * getAttributeName() method comments
                  */
                 $comments = array();
                 array_push($comments, 'Returns the attribute name');
                 array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::getAttributeName()');
                 array_push($comments, '@return string ' . $attribute->getCleanName());
                 array_push($_body, array('comment' => $comments));
                 /**
                  * getAttributeName() method body
                  */
                 array_push($_body, 'public function getAttributeName()');
                 array_push($_body, '{');
                 array_push($_body, 'return \'' . $attribute->getCleanName() . '\';');
                 array_push($_body, '}');
                 unset($comments, $model);
             }
             unset($attribute);
         }
         /**
          * __set_state method override
          */
         if (WsdlToPhpGenerator::getOptionGenerateWsdlClassFile()) {
             /**
              * __set_state() method comments
              */
             $comments = array();
             array_push($comments, 'Method called when an object has been exported with var_export() functions');
             array_push($comments, 'It allows to return an object instantiated with the values');
             array_push($comments, '@see ' . self::getGenericWsdlClassName() . '::__set_state()');
             array_push($comments, '@uses ' . self::getGenericWsdlClassName() . '::__set_state()');
             array_push($comments, '@param array $_array the exported values');
             array_push($comments, '@return ' . $this->getPackagedName());
             array_push($_body, array('comment' => $comments));
             unset($comments);
             /**
              * __set_state method body
              */
             array_push($_body, 'public static function __set_state(array $_array,$_className = __CLASS__)');
             array_push($_body, '{');
             array_push($_body, 'return parent::__set_state($_array,$_className);');
             array_push($_body, '}');
         }
     }
 }