/** * Returns the attributes of the struct and potentially from the parent class * @uses WsdlToPhpModel::getInheritance() * @uses WsdlToPhpModel::getModelByName() * @uses WsdlToPhpStruct::getIsStruct() * @uses WsdlToPhpStruct::getAttributes() * @param bool $_includeInheritanceAttributes include the attributes of parent class, default parent attributes are not included. If true, then the array is an associative array containing and index "attribute" for the WsdlToPhpStructAttribute object and an index "model" for the WsdlToPhpStruct object. * @param bool $_requiredFirst places the required attributes first, then the not required in order to have the _contrust method with the required attribute at first * @return array */ public function getAttributes($_includeInheritanceAttributes = false, $_requiredFirst = false) { $attributes = $this->attributes; /** * Returns the inherited attributes */ if ($_includeInheritanceAttributes) { $attributes = array(); if ($this->getInheritance() != '') { $model = WsdlToPhpModel::getModelByName($this->getInheritance()); while ($model && $model->getIsStruct()) { $modelAttributes = $model->getAttributes(); if (count($modelAttributes)) { foreach ($modelAttributes as $attribute) { array_push($attributes, array('attribute' => $attribute, 'model' => $model)); } } unset($modelAttributes); $model = WsdlToPhpModel::getModelByName($model->getInheritance()); } } $thisAttributes = $this->getAttributes(); if (count($thisAttributes)) { foreach ($thisAttributes as $attribute) { array_push($attributes, array('attribute' => $attribute, 'model' => $this)); } } unset($thisAttributes); } /** * Returns the required attributes at first position */ if ($_requiredFirst) { $requiredAttributes = array(); $notRequiredAttributes = array(); foreach ($attributes as $attribute) { $attributeModel = $_includeInheritanceAttributes ? $attribute['attribute'] : $attribute; if ($attributeModel->isRequired()) { array_push($requiredAttributes, $attribute); } else { array_push($notRequiredAttributes, $attribute); } } $attributes = array(); foreach ($requiredAttributes as $attribute) { array_push($attributes, $attribute); } foreach ($notRequiredAttributes as $attribute) { array_push($attributes, $attribute); } unset($requiredAttributes, $notRequiredAttributes); } return $attributes; }
/** * Manages union node * @uses WsdlToPhpGenerator::findSuitableParent() * @uses WsdlToPhpGenerator::setStructInheritance() * @uses DOMNode::hasAttributes() * @uses DOMNodeList::item() * @uses DOMElement::getAttribute() * @uses WsdlToPhpModel::getModelByName() * @uses WsdlToPhpModel::getInheritance() * @uses WsdlToPhpModel::getName() * @uses WsdlToPhpStruct::getIsStruct() * @uses WsdlToPhpStruct::getIsRestriction() * @param string $_wsdlLocation the wsdl location * @param DOMNode $_domNode the node * @param string $_fromWsdlLocation the wsdl location imported * @param string $_nodeNameMatch the name the node name must match, only when it's necessary to match a certain type of nodes * @return void */ protected function manageWsdlNodeUnion($_wsdlLocation = '', DOMNode $_domNode, $_fromWsdlLocation = '', $_nodeNameMatch = null) { if ($_domNode->hasAttributes()) { $parentNode = self::findSuitableParent($_domNode); if ($parentNode) { $parentNodeStruct = $this->getStruct($parentNode->getAttribute('name')); $attributes = $_domNode->attributes; $attributesCount = $attributes->length; for ($i = 0; $i < $attributesCount; $i++) { $attribute = $attributes->item($i); if ($attribute && stripos($attribute->nodeName, 'membertypes') !== false) { $nodeValue = $attribute->nodeValue; $nodeValues = explode(' ', $nodeValue); if (count($nodeValues)) { $nodeValueTypes = array(); foreach ($nodeValues as $nodeValueType) { $nodeValueType = explode(':', $nodeValueType); $nodeValueType = trim($nodeValueType[count($nodeValueType) - 1]); if (!empty($nodeValueType)) { $this->addStructMeta($parentNode->getAttribute('name'), 'union', array($nodeValueType)); $nodeValueTypeModel = WsdlToPhpModel::getModelByName($nodeValueType); while ($nodeValueTypeModel) { if ($nodeValueTypeModel->getIsRestriction()) { $nodeValueType = $nodeValueTypeModel->getName(); $nodeValueTypeModel = null; } elseif ($nodeValueTypeModel->getInheritance()) { $newNodeValueTypeModel = WsdlToPhpModel::getModelByName($nodeValueTypeModel->getInheritance()); if (!$newNodeValueTypeModel) { $nodeValueType = $nodeValueTypeModel->getInheritance(); } $nodeValueTypeModel = $newNodeValueTypeModel; } else { $nodeValueTypeModel = null; } } array_push($nodeValueTypes, $nodeValueType); } } $nodeValueTypes = array_unique($nodeValueTypes); if (count($nodeValueTypes) && $parentNodeStruct && !$parentNodeStruct->getInheritance()) { $this->setStructInheritance($parentNodeStruct->getName(), implode(',', $nodeValueTypes)); } } } } } } }