3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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)
32 * @copyright CiviCRM LLC (c) 2004-2016
34 class CRM_Extension_Info
{
37 * Extension info file name.
39 const FILENAME
= 'info.xml';
49 * Each item is a specification like:
50 * array('type'=>'psr4', 'namespace'=>'Foo\Bar', 'path'=>'/foo/bar').
52 public $classloader = array();
55 * Load extension info an XML file.
59 * @throws CRM_Extension_Exception_ParseException
60 * @return CRM_Extension_Info
62 public static function loadFromFile($file) {
63 list ($xml, $error) = CRM_Utils_XML
::parseFile($file);
65 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $error");
68 $instance = new CRM_Extension_Info();
69 $instance->parse($xml);
74 * Load extension info a string.
76 * @param string $string
79 * @throws CRM_Extension_Exception_ParseException
80 * @return CRM_Extension_Info
82 public static function loadFromString($string) {
83 list ($xml, $error) = CRM_Utils_XML
::parseString($string);
85 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string");
88 $instance = new CRM_Extension_Info();
89 $instance->parse($xml);
100 public function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) {
104 $this->label
= $label;
109 * Copy attributes from an XML document to $this
111 * @param SimpleXMLElement $info
113 public function parse($info) {
114 $this->key
= (string) $info->attributes()->key
;
115 $this->type
= (string) $info->attributes()->type
;
116 $this->file
= (string) $info->file
;
117 $this->label
= (string) $info->name
;
119 // Convert first level variables to CRM_Core_Extension properties
120 // and deeper into arrays. An exception for URLS section, since
121 // we want them in special format.
122 foreach ($info as $attr => $val) {
123 if (count($val->children()) == 0) {
124 $this->$attr = (string) $val;
126 elseif ($attr === 'urls') {
127 $this->urls
= array();
128 foreach ($val->url
as $url) {
129 $urlAttr = (string) $url->attributes()->desc
;
130 $this->urls
[$urlAttr] = (string) $url;
134 elseif ($attr === 'classloader') {
135 $this->classloader
= array();
136 foreach ($val->psr4
as $psr4) {
137 $this->classloader
[] = array(
139 'prefix' => (string) $psr4->attributes()->prefix
,
140 'path' => (string) $psr4->attributes()->path
,
145 $this->$attr = CRM_Utils_XML
::xmlObjToArray($val);