parse($xml); return $instance; } /** * Load extension info a string * * @param string $string XML content * * @throws CRM_Extension_Exception_ParseException * @return CRM_Extension_Info */ public static function loadFromString($string) { list ($xml, $error) = CRM_Utils_XML::parseString($string); if ($xml === FALSE) { throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string"); } $instance = new CRM_Extension_Info(); $instance->parse($xml); return $instance; } function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) { $this->key = $key; $this->type = $type; $this->name = $name; $this->label = $label; $this->file = $file; } /** * Copy attributes from an XML document to $this * * @param SimpleXMLElement $info * @return void */ public function parse($info) { $this->key = (string) $info->attributes()->key; $this->type = (string) $info->attributes()->type; $this->file = (string) $info->file; $this->label = (string) $info->name; // Convert first level variables to CRM_Core_Extension properties // and deeper into arrays. An exception for URLS section, since // we want them in special format. foreach ($info as $attr => $val) { if (count($val->children()) == 0) { $this->$attr = (string) $val; } elseif ($attr === 'urls') { $this->urls = array(); foreach ($val->url as $url) { $urlAttr = (string) $url->attributes()->desc; $this->urls[$urlAttr] = (string) $url; } ksort($this->urls); } else { $this->$attr = CRM_Utils_XML::xmlObjToArray($val); } } } }