Issue #3483: parent_id not always available as index
[civicrm-core.git] / CRM / Extension / MixInfo.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * "Mixins" allow extensions to be initialized with small, reusable chunks of code.
14 *
15 * Example: A mixin might scan an extension for YAML files, aggregate them, add that
16 * to the boot-cache, and use the results to register event-listeners during initialization.
17 *
18 * Mixins have the following characteristics:
19 *
20 * - They are defined by standalone PHP files, e.g. `civix@1.0.2.mixin.php`
21 * - They are implicitly versioned via strict SemVer. (`1.1.0` can replace `1.0.0`; `2.0.0` and `1.0.0` are separate/parallel things).
22 * - They are activated via `info.xml` (`<mix>civix@1.0</mix>`).
23 * - They may be copied/reproduced in multiple extensions.
24 * - They are de-duped - such that a major-version (eg `civix@1` or `civix@2`) is only loaded once.
25 *
26 * The "MixInfo" record tracks the mixins needed by an extension. You may consider this an
27 * optimized subset of the 'info.xml'. (The mix-info is loaded on every page-view, so this
28 * record is serialized and stored in the MixinLoader cache.)
29 */
30 class CRM_Extension_MixInfo {
31
32 /**
33 * @var string
34 *
35 * Ex: 'org.civicrm.flexmailer'
36 */
37 public $longName;
38
39 /**
40 * @var string
41 *
42 * Ex: 'flexmailer'
43 */
44 public $shortName;
45
46 /**
47 * @var string|null
48 *
49 * Ex: '/var/www/modules/civicrm/ext/flexmailer'.
50 */
51 public $path;
52
53 /**
54 * @var array
55 * Ex: ['civix@2.0', 'menu@1.0']
56 */
57 public $mixins;
58
59 /**
60 * Get a path relative to the target extension.
61 *
62 * @param string $relPath
63 * @return string
64 */
65 public function getPath($relPath = NULL) {
66 return $relPath === NULL ? $this->path : $this->path . DIRECTORY_SEPARATOR . ltrim($relPath, '/');
67 }
68
69 public function isActive() {
70 return \CRM_Extension_System::singleton()->getMapper()->isActiveModule($this->shortName);
71 }
72
73 }