Merge pull request #18136 from demeritcowboy/deprecated-hook-invoke
[civicrm-core.git] / CRM / Core / Module.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 * A module is any software package that participates in the hook
14 * system, such as CiviCRM Module-Extension, a Drupal Module, or
15 * a Joomla Plugin.
16 *
17 * @package CRM
18 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 */
20 class CRM_Core_Module {
21
22 /**
23 * @var string
24 */
25 public $name;
26
27 /**
28 * Is the module enabled.
29 *
30 * @var bool
31 */
32 public $is_active;
33
34 /**
35 * Class constructor.
36 *
37 * @param string $name
38 * @param bool $is_active
39 */
40 public function __construct($name, $is_active) {
41 $this->name = $name;
42 $this->is_active = $is_active;
43 }
44
45 /**
46 * Get a list of all known modules.
47 *
48 * @param bool $fresh
49 * Force new results?
50 *
51 * @return array
52 */
53 public static function getAll($fresh = FALSE) {
54 static $result;
55 if ($fresh || !is_array($result)) {
56 $result = CRM_Extension_System::singleton()->getMapper()->getModules();
57 // pseudo-module for core
58 $result[] = new CRM_Core_Module('civicrm', TRUE);
59
60 $config = CRM_Core_Config::singleton();
61 $result = array_merge($result, $config->userSystem->getModules());
62 }
63 return $result;
64 }
65
66 /**
67 * Get the status for each module.
68 *
69 * @param array $modules
70 * Array(CRM_Core_Module).
71 * @return array
72 * Array(string $moduleName => string $statusCode).
73 * @see CRM_Extension_Manager::STATUS_INSTALLED
74 * @see CRM_Extension_Manager::STATUS_DISABLED
75 */
76 public static function collectStatuses($modules) {
77 $statuses = [];
78 foreach ($modules as $module) {
79 $statuses[$module->name] = $module->is_active ? CRM_Extension_Manager::STATUS_INSTALLED : CRM_Extension_Manager::STATUS_DISABLED;
80
81 }
82 return $statuses;
83 }
84
85 }