00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Api_Model_Wsdl_Config_Element extends Varien_Simplexml_Element
00035 {
00036 public function extend($source, $overwrite=false)
00037 {
00038 if (!$source instanceof Varien_Simplexml_Element) {
00039 return $this;
00040 }
00041
00042 foreach ($this->getChildren($source) as $namespace => $children) {
00043 foreach ($children as $child) {
00044 $this->extendChild($child, $overwrite, $namespace);
00045 }
00046 }
00047
00048 return $this;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058 public function extendChild($source, $overwrite=false, $elmNamespace = '')
00059 {
00060
00061 $targetChild = null;
00062
00063
00064 $sourceName = $source->getName();
00065
00066
00067 $sourceChildren = $this->getChildren($source);
00068
00069 if ($elmNamespace == '') {
00070 $elmNamespace = null;
00071 }
00072
00073 if (!$source->hasChildren()) {
00074
00075 $elm = $this->getElementByName($source, $elmNamespace);
00076 if (!is_null($elm)) {
00077
00078
00079 if ($this->getChildren($elm)) {
00080 return $this;
00081 }
00082 if ($overwrite) {
00083
00084 unset($elm);
00085 } else {
00086 return $this;
00087 }
00088 }
00089 $targetChild = $this->addChild($sourceName, $source->xmlentities(), $elmNamespace);
00090 $targetChild->setParent($this);
00091 foreach ($this->getAttributes($source) as $namespace => $attributes) {
00092 foreach ($attributes as $key => $value) {
00093 $_namespacesPrefix = Mage_Api_Model_Wsdl_Config::getNamespacesPrefix();
00094 if ($namespace == '') {
00095 $namespace = null;
00096 } elseif (array_key_exists($namespace, $_namespacesPrefix)) {
00097 $key = $_namespacesPrefix[$namespace] . ':' . $key;
00098 }
00099
00100 $targetChild->addAttribute($key, $this->xmlentities($value), $namespace);
00101 }
00102 }
00103 return $this;
00104 }
00105
00106 $elm = $this->getElementByName($source, $elmNamespace);
00107 if (!is_null($elm)) {
00108 $targetChild = $elm;
00109 }
00110 if (is_null($targetChild)) {
00111
00112 $targetChild = $this->addChild($sourceName, null, $elmNamespace);
00113 $targetChild->setParent($this);
00114 foreach ($this->getAttributes($source) as $namespace => $attributes) {
00115 foreach ($attributes as $key => $value) {
00116 $_namespacesPrefix = Mage_Api_Model_Wsdl_Config::getNamespacesPrefix();
00117 if ($namespace == '') {
00118 $namespace = null;
00119 } elseif (array_key_exists($namespace, $_namespacesPrefix)) {
00120 $key = $_namespacesPrefix[$namespace] . ':' . $key;
00121 }
00122 $targetChild->addAttribute($key, $this->xmlentities($value), $namespace);
00123 }
00124 }
00125 }
00126
00127 foreach ($sourceChildren as $elmNamespace => $children) {
00128 foreach ($children as $childKey => $childNode) {
00129 $targetChild->extendChild($childNode, $overwrite, $elmNamespace);
00130 }
00131 }
00132
00133 return $this;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 public function getAttributes($source, $namespace = null)
00150 {
00151 $attributes = array();
00152 if (!is_null($namespace)) {
00153 $attributes[$namespace] = $source->attributes($namespace);
00154 return $attributes;
00155 }
00156 $namespaces = $source->getNamespaces(true);
00157 $attributes[''] = $source->attributes('');
00158 foreach ($namespaces as $key => $value) {
00159 if ($key == '' || $key == 'soap') {
00160 continue;
00161 }
00162 $attributes[$value] = $source->attributes($value);
00163 }
00164 return $attributes;
00165 }
00166
00167
00168
00169
00170
00171
00172 public function getChildren($source)
00173 {
00174 $children = array();
00175 $namespaces = $source->getNamespaces(true);
00176 foreach ($namespaces as $key => $value) {
00177 if ($key == '' || $key == 'wsdl') {
00178 continue;
00179 }
00180 $children[$value] = $source->children($value);
00181 }
00182 $children[''] = $source->children('');
00183 return $children;
00184 }
00185
00186
00187
00188
00189
00190
00191 public function hasChildren()
00192 {
00193 if (!$this->getChildren($this)) {
00194 return false;
00195 }
00196
00197
00198 foreach ($this->getChildren($this) as $namespace => $children) {
00199 foreach ($children as $k => $child) {
00200 return true;
00201 }
00202 }
00203 return false;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 public function getElementByName($source, $elmNamespace = '')
00214 {
00215 $sourceName = $source->getName();
00216 $extendElmAttributes = $this->getAttributes($source);
00217 foreach ($this->children($elmNamespace) as $k => $child) {
00218 if ($child->getName() == $sourceName) {
00219 $elm = true;
00220 foreach ($extendElmAttributes as $namespace => $attributes) {
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 foreach ($attributes as $key => $value) {
00232 if (is_null($child->getAttribute($key, $namespace)) || $child->getAttribute($key, $namespace) != $value) {
00233 $elm = false;
00234 }
00235 }
00236 }
00237
00238
00239
00240
00241 if (!count($extendElmAttributes) && count($this->getAttributes($child))) {
00242 $elm = false;
00243 }
00244 if ($elm) {
00245 return $child;
00246 }
00247 }
00248 }
00249 return null;
00250 }
00251
00252
00253
00254
00255
00256
00257 public function getAttribute($name, $namespace = ''){
00258 $attrs = $this->attributes($namespace);
00259 return isset($attrs[$name]) ? (string)$attrs[$name] : null;
00260 }
00261
00262 }