3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Metadata for an extension (e.g. the extension's "info.xml" file)
31 class CRM_Extension_Info
{
34 * Extension info file name
36 const FILENAME
= 'info.xml';
45 * Load extension info an XML file
47 * @param string $string XML content
48 * @return CRM_Extension_Info
49 * @throws CRM_Extension_Exception
51 public static function loadFromFile($file) {
52 list ($xml, $error) = CRM_Utils_XML
::parseFile($file);
54 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $error");
57 $instance = new CRM_Extension_Info();
58 $instance->parse($xml);
63 * Load extension info a string
65 * @param string $string XML content
66 * @return CRM_Extension_Info
68 public static function loadFromString($string) {
69 list ($xml, $error) = CRM_Utils_XML
::parseString($string);
71 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string");
74 $instance = new CRM_Extension_Info();
75 $instance->parse($xml);
79 function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) {
83 $this->label
= $label;
88 * Copy attributes from an XML document to $this
90 * @param SimpleXMLElement $info
93 public function parse($info) {
94 $this->key
= (string) $info->attributes()->key
;
95 $this->type
= (string) $info->attributes()->type
;
96 $this->file
= (string) $info->file
;
97 $this->label
= (string) $info->name
;
99 // Convert first level variables to CRM_Core_Extension properties
100 // and deeper into arrays. An exception for URLS section, since
101 // we want them in special format.
102 foreach ($info as $attr => $val) {
103 if (count($val->children()) == 0) {
104 $this->$attr = (string) $val;
106 elseif ($attr === 'urls') {
107 $this->urls
= array();
108 foreach ($val->url
as $url) {
109 $urlAttr = (string) $url->attributes()->desc
;
110 $this->urls
[$urlAttr] = (string) $url;
115 $this->$attr = CRM_Utils_XML
::xmlObjToArray($val);