コード例 #1
0
 /**
  * Returns the array of lines to declare the getter
  * @uses WsdlToPhpModel::getModelByName()
  * @uses WsdlToPhpModel::getCleanName()
  * @uses WsdlToPhpModel::nameIsClean()
  * @uses WsdlToPhpModel::getName()
  * @uses WsdlToPhpModel::getPackagedName()
  * @uses WsdlToPhpStruct::getIsStruct()
  * @uses WsdlToPhpStructAttribute::getType()
  * @uses WsdlToPhpStructAttribute::getGetterName()
  * @uses WsdlToPhpStructAttribute::isRequired()
  * @uses WsdlToPhpStructAttribute::getOwner()
  * @param array $_body
  * @param WsdlToPhpStruct $_struct
  * @return void
  */
 public function getGetterDeclaration(&$_body, WsdlToPhpStruct $_struct)
 {
     $model = self::getModelByName($this->getType());
     $isXml = $this->getType() == 'DOMDocument';
     /**
      * get() method comment
      */
     $comments = array();
     array_push($comments, 'Get ' . $this->getName() . ' value');
     if ($isXml) {
         array_push($comments, '@uses DOMDocument::loadXML()');
         array_push($comments, '@uses DOMDocument::hasChildNodes()');
         array_push($comments, '@uses DOMDocument::saveXML()');
         array_push($comments, '@uses DOMNode::item()');
         array_push($comments, '@uses ' . $_struct->getPackagedName() . '::' . $this->getSetterName() . '()');
         array_push($comments, '@param bool true or false whether to return XML value as string or as DOMDocument');
     }
     array_push($comments, '@return ' . ($model ? $model->getIsStruct() && $model->getPackagedName() != $this->getOwner()->getPackagedName() ? $model->getPackagedName() : ($model->getInheritance() ? $model->getInheritance() : $this->getType()) : $this->getType()) . ($this->isRequired() ? '' : '|null'));
     array_push($_body, array('comment' => $comments));
     /**
      * get() method body
      */
     array_push($_body, 'public function ' . $this->getGetterName() . '(' . ($isXml ? '$_asString = true' : '') . ')');
     array_push($_body, "{");
     $thisAccess = '';
     if ($this->nameIsClean()) {
         $thisAccess = '$this->' . $this->getName();
     } else {
         $thisAccess = '$this->{\'' . addslashes($this->getName()) . '\'}';
     }
     /**
      * format XML data
      */
     if ($isXml) {
         array_push($_body, 'if(!empty(' . $thisAccess . ') && !(' . $thisAccess . ' instanceof DOMDocument))');
         array_push($_body, '{');
         array_push($_body, '$dom = new DOMDocument(\'1.0\',\'UTF-8\');');
         array_push($_body, '$dom->formatOutput = true;');
         array_push($_body, 'if($dom->loadXML(' . $thisAccess . '))');
         array_push($_body, '{');
         array_push($_body, '$this->' . $this->getSetterName() . '($dom);');
         array_push($_body, '}');
         array_push($_body, 'unset($dom);');
         array_push($_body, '}');
     }
     if ($isXml) {
         array_push($_body, 'return ($_asString && (' . $thisAccess . ' instanceof DOMDocument) && ' . $thisAccess . '->hasChildNodes())?' . $thisAccess . '->saveXML(' . $thisAccess . '->childNodes->item(0)):' . $thisAccess . ';');
     } else {
         array_push($_body, 'return ' . $thisAccess . ';');
     }
     array_push($_body, "}");
     unset($model, $isXml, $comments);
 }