]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Renamed XmlElement changes to ElggXMLElement. Fixed plugin manifest parsing.
authorBrett Profitt <brett.profitt@gmail.com>
Wed, 5 Dec 2012 23:30:10 +0000 (18:30 -0500)
committerBrett Profitt <brett.profitt@gmail.com>
Wed, 5 Dec 2012 23:30:10 +0000 (18:30 -0500)
engine/classes/ElggPluginManifest.php
engine/classes/ElggXMLElement.php [new file with mode: 0644]
engine/classes/XmlElement.php
engine/lib/xml.php

index a4f5bb95dd9084a5a7eaa71244db312f381285ab..6912c2b08ab5ef2420c9a727050427f8e725d3a5 100644 (file)
@@ -130,7 +130,7 @@ class ElggPluginManifest {
                }
 
                // see if we need to construct the xml object.
-               if ($manifest instanceof XmlElement) {
+               if ($manifest instanceof ElggXMLElement) {
                        $manifest_obj = $manifest;
                } else {
                        if (substr(trim($manifest), 0, 1) == '<') {
diff --git a/engine/classes/ElggXMLElement.php b/engine/classes/ElggXMLElement.php
new file mode 100644 (file)
index 0000000..65a1391
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/**
+ * A parser for XML that uses SimpleXMLElement
+ *
+ * @package    Elgg.Core
+ * @subpackage XML
+ */
+class ElggXMLElement {
+       /**
+        * @var SimpleXMLElement
+        */
+       private $_element;
+
+       /**
+        * Creates an ElggXMLParser from a string or existing SimpleXMLElement
+        * 
+        * @param string|SimpleXMLElement $xml The XML to parse
+        */
+       public function __construct($xml) {
+               if ($xml instanceof SimpleXMLElement) {
+                       $this->_element = $xml;
+               } else {
+                       $this->_element = new SimpleXMLElement($xml);
+               }
+       }
+
+       /**
+        * @return string The name of the element
+        */
+       public function getName() {
+               return $this->_element->getName();
+       }
+
+       /**
+        * @return array:string The attributes
+        */
+       public function getAttributes() {
+               //include namespace declarations as attributes
+               $xmlnsRaw = $this->_element->getNamespaces();
+               $xmlns = array();
+               foreach ($xmlnsRaw as $key => $val) {
+                       $label = 'xmlns' . ($key ? ":$key" : $key);
+                       $xmlns[$label] = $val;
+               }
+               //get attributes and merge with namespaces
+               $attrRaw = $this->_element->attributes();
+               $attr = array();
+               foreach ($attrRaw as $key => $val) {
+                       $attr[$key] = $val;
+               }
+               $attr = array_merge((array) $xmlns, (array) $attr);
+               $result = array();
+               foreach ($attr as $key => $val) {
+                       $result[$key] = (string) $val;
+               }
+               return $result;
+       }
+
+       /**
+        * @return string CData
+        */
+       public function getContent() {
+               return (string) $this->_element;
+       }
+
+       /**
+        * @return array:ElggXMLElement Child elements
+        */
+       public function getChildren() {
+               $children = $this->_element->children();
+               $result = array();
+               foreach ($children as $val) {
+                       $result[] = new ElggXMLElement($val);
+               }
+
+               return $result;
+       }
+
+       function __get($name) {
+               switch ($name) {
+                       case 'name':
+                               return $this->getName();
+                               break;
+                       case 'attributes':
+                               return $this->getAttributes();
+                               break;
+                       case 'content':
+                               return $this->getContent();
+                               break;
+                       case 'children':
+                               return $this->getChildren();
+                               break;
+               }
+               return null;
+       }
+
+       function __isset($name) {
+               switch ($name) {
+                       case 'name':
+                               return $this->getName() !== null;
+                               break;
+                       case 'attributes':
+                               return $this->getAttributes() !== null;
+                               break;
+                       case 'content':
+                               return $this->getContent() !== null;
+                               break;
+                       case 'children':
+                               return $this->getChildren() !== null;
+                               break;
+               }
+               return false;
+       }
+
+}
\ No newline at end of file
index eb798773184e4aa2189b792c79debd9996c3a4fc..280bba66472287ffd41a7b1ad2e9ca8ec070c168 100644 (file)
  * @subpackage XML
  */
 class XmlElement {
-       /**
-       * @var SimpleXMLElement
-        */
-       private $_element;
-       
-       /**
-        * Creates XmlElement from string or existing SimpleXMLElement
-        * @param string|SimpleXMLElement $xml
-        */
-       public function __construct($xml) {
-               if ($xml instanceof SimpleXMLElement) {
-                       $this->_element = $xml;
-               } else {
-                       $this->_element = new SimpleXMLElement($xml);
-               }
-       }
-       
-       /** 
-        * @return string The name of the element 
-        */
-       public function getName() {
-               return $this->_element->getName();
-       }
-       
-       /** 
-        * @return array:string The attributes 
-        */
-       public function getAttributes() {
-               //include namespace declarations as attributes
-               $xmlnsRaw = $this->_element->getNamespaces();
-               $xmlns = array();
-               foreach ($xmlnsRaw as $key => $val) {
-                       $label = 'xmlns'.($key?":$key":$key);
-                       $xmlns[$label] = $val;
-               }
-               //get attributes and merge with namespaces
-               $attrRaw = $this->_element->attributes();
-               $attr = array();
-               foreach ($attrRaw as $key => $val) {
-                       $attr[$key] = $val;
-               }
-               $attr = array_merge((array)$xmlns, (array)$attr);
-               $result = array();
-               foreach ($attr as $key => $val) {
-                       $result[$key] = (string)$val;
-               }
-               return $result;
-       }
-       
-       /** 
-        * @return string CData 
-        */
-       public function getContent() {
-               return (string)$this->_element;
-       }
-       
-       /** 
-        * @return array:XmlElement Child elements 
-        */
-       public function getChildren() {
-               $children = $this->_element->children();
-               $result = array();
-               foreach ($children as $val) {
-                       $result[] = new XmlElement($val);
-               }
-               return $result;
-       }
+       /** The name of the element */
+       public $name;
 
-       function __get($name) {
-               switch ($name) {
-                       case 'name':
-                               return $this->getName();
-                               break;
-                       case 'attributes':
-                               return $this->getAttributes();
-                               break;
-                       case 'content':
-                               return $this->getContent();
-                               break;
-                       case 'children':
-                               return $this->getChildren();
-                               break;          
-               }
-               return null;
-       }
-       
-       function __isset($name) {
-               switch ($name) {
-                       case 'name':
-                               return $this->getName()!==null;
-                               break;
-                       case 'attributes':
-                               return $this->getAttributes()!==null;
-                               break;
-                       case 'content':
-                               return $this->getContent()!==null;
-                               break;
-                       case 'children':
-                               return $this->getChildren()!==null;
-                               break;
-               }
-               return false;
-       }
+       /** The attributes */
+       public $attributes;
+
+       /** CData */
+       public $content;
+
+       /** Child elements */
+       public $children;
 };
index 4f1ae76a90503a7d902af30bde8b572755e2b799..ff82d7e8a9228c336adef6309811ec6973375042 100644 (file)
@@ -107,5 +107,5 @@ function serialise_array_to_xml(array $data, $n = 0) {
  * @return object
  */
 function xml_to_object($xml) {
-       return new XmlElement($xml);
+       return new ElggXMLElement($xml);
 }