3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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();
56 * Each item is they key-name of an extension required by this extension.
58 public $requires = array();
61 * Load extension info an XML file.
65 * @throws CRM_Extension_Exception_ParseException
66 * @return CRM_Extension_Info
68 public static function loadFromFile($file) {
69 list ($xml, $error) = CRM_Utils_XML
::parseFile($file);
71 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $error");
74 $instance = new CRM_Extension_Info();
75 $instance->parse($xml);
80 * Load extension info a string.
82 * @param string $string
85 * @throws CRM_Extension_Exception_ParseException
86 * @return CRM_Extension_Info
88 public static function loadFromString($string) {
89 list ($xml, $error) = CRM_Utils_XML
::parseString($string);
91 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string");
94 $instance = new CRM_Extension_Info();
95 $instance->parse($xml);
100 * Build a reverse-dependency map.
102 * @param array $infos
103 * The universe of available extensions.
104 * Ex: $infos['org.civicrm.foobar'] = new CRM_Extension_Info().
106 * If "org.civicrm.api" is required by "org.civicrm.foo", then return
107 * array('org.civicrm.api' => array(CRM_Extension_Info[org.civicrm.foo])).
108 * Array(string $key => array $requiredBys).
110 public static function buildReverseMap($infos) {
112 foreach ($infos as $info) {
113 foreach ($info->requires
as $key) {
114 $revMap[$key][] = $info;
127 public function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) {
131 $this->label
= $label;
136 * Copy attributes from an XML document to $this
138 * @param SimpleXMLElement $info
140 public function parse($info) {
141 $this->key
= (string) $info->attributes()->key
;
142 $this->type
= (string) $info->attributes()->type
;
143 $this->file
= (string) $info->file
;
144 $this->label
= (string) $info->name
;
146 // Convert first level variables to CRM_Core_Extension properties
147 // and deeper into arrays. An exception for URLS section, since
148 // we want them in special format.
149 foreach ($info as $attr => $val) {
150 if (count($val->children()) == 0) {
151 $this->$attr = (string) $val;
153 elseif ($attr === 'urls') {
154 $this->urls
= array();
155 foreach ($val->url
as $url) {
156 $urlAttr = (string) $url->attributes()->desc
;
157 $this->urls
[$urlAttr] = (string) $url;
161 elseif ($attr === 'classloader') {
162 $this->classloader
= array();
163 foreach ($val->psr4
as $psr4) {
164 $this->classloader
[] = array(
166 'prefix' => (string) $psr4->attributes()->prefix
,
167 'path' => (string) $psr4->attributes()->path
,
171 elseif ($attr === 'requires') {
172 $this->requires
= array();
173 foreach ($val->ext
as $ext) {
174 $this->requires
[] = (string) $ext;
178 $this->$attr = CRM_Utils_XML
::xmlObjToArray($val);