3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
34 class CRM_Extension_Info
{
37 * Extension info file name.
39 const FILENAME
= 'info.xml';
52 * Each item is a specification like:
53 * array('type'=>'psr4', 'namespace'=>'Foo\Bar', 'path'=>'/foo/bar').
55 public $classloader = [];
59 * Each item is they key-name of an extension required by this extension.
61 public $requires = [];
64 * Load extension info an XML file.
68 * @throws CRM_Extension_Exception_ParseException
69 * @return CRM_Extension_Info
71 public static function loadFromFile($file) {
72 list ($xml, $error) = CRM_Utils_XML
::parseFile($file);
74 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $error");
77 $instance = new CRM_Extension_Info();
78 $instance->parse($xml);
83 * Load extension info a string.
85 * @param string $string
88 * @throws CRM_Extension_Exception_ParseException
89 * @return CRM_Extension_Info
91 public static function loadFromString($string) {
92 list ($xml, $error) = CRM_Utils_XML
::parseString($string);
94 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string");
97 $instance = new CRM_Extension_Info();
98 $instance->parse($xml);
103 * Build a reverse-dependency map.
105 * @param array $infos
106 * The universe of available extensions.
107 * Ex: $infos['org.civicrm.foobar'] = new CRM_Extension_Info().
109 * If "org.civicrm.api" is required by "org.civicrm.foo", then return
110 * array('org.civicrm.api' => array(CRM_Extension_Info[org.civicrm.foo])).
111 * Array(string $key => array $requiredBys).
113 public static function buildReverseMap($infos) {
115 foreach ($infos as $info) {
116 foreach ($info->requires
as $key) {
117 $revMap[$key][] = $info;
130 public function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) {
134 $this->label
= $label;
139 * Copy attributes from an XML document to $this
141 * @param SimpleXMLElement $info
143 public function parse($info) {
144 $this->key
= (string) $info->attributes()->key
;
145 $this->type
= (string) $info->attributes()->type
;
146 $this->file
= (string) $info->file
;
147 $this->label
= (string) $info->name
;
149 // Convert first level variables to CRM_Core_Extension properties
150 // and deeper into arrays. An exception for URLS section, since
151 // we want them in special format.
152 foreach ($info as $attr => $val) {
153 if (count($val->children()) == 0) {
154 $this->$attr = (string) $val;
156 elseif ($attr === 'urls') {
158 foreach ($val->url
as $url) {
159 $urlAttr = (string) $url->attributes()->desc
;
160 $this->urls
[$urlAttr] = (string) $url;
164 elseif ($attr === 'classloader') {
165 $this->classloader
= [];
166 foreach ($val->psr4
as $psr4) {
167 $this->classloader
[] = [
169 'prefix' => (string) $psr4->attributes()->prefix
,
170 'path' => (string) $psr4->attributes()->path
,
174 elseif ($attr === 'requires') {
175 $this->requires
= $this->filterRequirements($val);
178 $this->$attr = CRM_Utils_XML
::xmlObjToArray($val);
184 * Filter out invalid requirements, e.g. extensions that have been moved to core.
186 * @param SimpleXMLElement $requirements
189 public function filterRequirements($requirements) {
191 $compatInfo = CRM_Extension_System
::getCompatibilityInfo();
192 foreach ($requirements->ext
as $ext) {
193 $ext = (string) $ext;
194 if (empty($compatInfo[$ext]['obsolete'])) {