fddd975f496cea5c003a0d2c89f16cac00e649a7
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Metadata for an extension (e.g. the extension's "info.xml" file)
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 class CRM_Extension_Info
{
21 * Extension info file name.
23 const FILENAME
= 'info.xml';
36 * Each item is a specification like:
37 * array('type'=>'psr4', 'namespace'=>'Foo\Bar', 'path'=>'/foo/bar').
39 public $classloader = [];
43 * Each item is they key-name of an extension required by this extension.
45 public $requires = [];
48 * Load extension info an XML file.
52 * @throws CRM_Extension_Exception_ParseException
53 * @return CRM_Extension_Info
55 public static function loadFromFile($file) {
56 list ($xml, $error) = CRM_Utils_XML
::parseFile($file);
58 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $error");
61 $instance = new CRM_Extension_Info();
62 $instance->parse($xml);
67 * Load extension info a string.
69 * @param string $string
72 * @throws CRM_Extension_Exception_ParseException
73 * @return CRM_Extension_Info
75 public static function loadFromString($string) {
76 list ($xml, $error) = CRM_Utils_XML
::parseString($string);
78 throw new CRM_Extension_Exception_ParseException("Failed to parse info XML: $string");
81 $instance = new CRM_Extension_Info();
82 $instance->parse($xml);
87 * Build a reverse-dependency map.
90 * The universe of available extensions.
91 * Ex: $infos['org.civicrm.foobar'] = new CRM_Extension_Info().
93 * If "org.civicrm.api" is required by "org.civicrm.foo", then return
94 * array('org.civicrm.api' => array(CRM_Extension_Info[org.civicrm.foo])).
95 * Array(string $key => array $requiredBys).
97 public static function buildReverseMap($infos) {
99 foreach ($infos as $info) {
100 foreach ($info->requires
as $key) {
101 $revMap[$key][] = $info;
114 public function __construct($key = NULL, $type = NULL, $name = NULL, $label = NULL, $file = NULL) {
118 $this->label
= $label;
123 * Copy attributes from an XML document to $this
125 * @param SimpleXMLElement $info
127 public function parse($info) {
128 $this->key
= (string) $info->attributes()->key
;
129 $this->type
= (string) $info->attributes()->type
;
130 $this->file
= (string) $info->file
;
131 $this->label
= (string) $info->name
;
133 // Convert first level variables to CRM_Core_Extension properties
134 // and deeper into arrays. An exception for URLS section, since
135 // we want them in special format.
136 foreach ($info as $attr => $val) {
137 if (count($val->children()) == 0) {
138 $this->$attr = (string) $val;
140 elseif ($attr === 'urls') {
142 foreach ($val->url
as $url) {
143 $urlAttr = (string) $url->attributes()->desc
;
144 $this->urls
[$urlAttr] = (string) $url;
148 elseif ($attr === 'classloader') {
149 $this->classloader
= [];
150 foreach ($val->psr4
as $psr4) {
151 $this->classloader
[] = [
153 'prefix' => (string) $psr4->attributes()->prefix
,
154 'path' => (string) $psr4->attributes()->path
,
158 elseif ($attr === 'requires') {
159 $this->requires
= $this->filterRequirements($val);
162 $this->$attr = CRM_Utils_XML
::xmlObjToArray($val);
168 * Filter out invalid requirements, e.g. extensions that have been moved to core.
170 * @param SimpleXMLElement $requirements
173 public function filterRequirements($requirements) {
175 $compatInfo = CRM_Extension_System
::getCompatibilityInfo();
176 foreach ($requirements->ext
as $ext) {
177 $ext = (string) $ext;
178 if (empty($compatInfo[$ext]['obsolete'])) {