Mage_Api_Model_Wsdl_Config_Element Class Reference

Inheritance diagram for Mage_Api_Model_Wsdl_Config_Element:

Varien_Simplexml_Element

List of all members.

Public Member Functions

 extend ($source, $overwrite=false)
 extendChild ($source, $overwrite=false, $elmNamespace= '')
 getAttributes ($source, $namespace=null)
 getChildren ($source)
 hasChildren ()
 getElementByName ($source, $elmNamespace= '')
 getAttribute ($name, $namespace= '')


Detailed Description

Definition at line 34 of file Element.php.


Member Function Documentation

extend ( source,
overwrite = false 
)

Extends current node with xml from $source

If $overwrite is false will merge only missing nodes Otherwise will overwrite existing nodes

Parameters:
Varien_Simplexml_Element $source
boolean $overwrite
Returns:
Varien_Simplexml_Element

Reimplemented from Varien_Simplexml_Element.

Definition at line 36 of file Element.php.

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     }

extendChild ( source,
overwrite = false,
elmNamespace = '' 
)

Extends one node

Parameters:
Varien_Simplexml_Element $source
boolean $overwrite
Returns:
Varien_Simplexml_Element

Definition at line 58 of file Element.php.

00059     {
00060         // this will be our new target node
00061         $targetChild = null;
00062 
00063         // name of the source node
00064         $sourceName = $source->getName();
00065 
00066         // here we have children of our source node
00067         $sourceChildren = $this->getChildren($source);
00068 
00069         if ($elmNamespace == '') {
00070             $elmNamespace = null;
00071         }
00072 
00073         if (!$source->hasChildren()) {
00074             // handle string node
00075             $elm = $this->getElementByName($source, $elmNamespace);
00076             if (!is_null($elm)) {
00077 
00078                 // if target already has children return without regard
00079                 if ($this->getChildren($elm)) {
00080                     return $this;
00081                 }
00082                 if ($overwrite) {
00083 //                    unset($this->$sourceName);
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             // if child target is not found create new and descend
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     }

getAttribute ( name,
namespace = '' 
)

Returns attribute value by attribute name

Returns:
string

Definition at line 257 of file Element.php.

00257                                                         {
00258         $attrs = $this->attributes($namespace);
00259         return isset($attrs[$name]) ? (string)$attrs[$name] : null;
00260     }

getAttributes ( source,
namespace = null 
)

Return attributes of all namespaces

array( namespace => array( attribute_key => attribute_value, ... ) )

Parameters:
Varien_Simplexml_Element $source
Returns:
array

Definition at line 149 of file Element.php.

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     }

getChildren ( source  ) 

Return children of all namespaces

Parameters:
Varien_Simplexml_Element $source

Definition at line 172 of file Element.php.

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     }

getElementByName ( source,
elmNamespace = '' 
)

Return element by tag name, and checking attributes with namespaces

Parameters:
Varien_Simplexml_Element $source
string $namespace
Returns:
null|Varien_Simplexml_Element

if count of attributes of extend element is 0 in $namespace, and current element has attributes in $namespace - different elements

if count of namespaces attributes of element to extend is 0, but current element has namespaces attributes - different elements

Definition at line 213 of file Element.php.

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                      * if count of attributes of extend element is 0 in $namespace,
00223                      * and current element has attributes in $namespace - different elements
00224                      */
00225 //                    if (!count($attributes) && count($this->getAttributes($child, $namespace))) {
00226 //                        foreach ($this->getAttributes($child, $namespace) as $attribute) {
00227 //                            $elm = false;
00228 //                            break;
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                  * if count of namespaces attributes of element to extend is 0,
00239                  * but current element has namespaces attributes - different elements
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     }

hasChildren (  ) 

Return if has children

Returns:
boolean

Reimplemented from Varien_Simplexml_Element.

Definition at line 191 of file Element.php.

00192     {
00193         if (!$this->getChildren($this)) {
00194             return false;
00195         }
00196 
00197         // simplexml bug: @attributes is in children() but invisible in foreach
00198         foreach ($this->getChildren($this) as $namespace => $children) {
00199             foreach ($children as $k => $child) {
00200                 return true;
00201             }
00202         }
00203         return false;
00204     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:33 2009 for Magento by  doxygen 1.5.8