Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CiviCRM_Hook | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id: $ | |
34 | * | |
35 | */ | |
36 | class CRM_Utils_Hook_Drupal6 extends CRM_Utils_Hook { | |
37 | ||
38 | /** | |
39 | * @var bool | |
40 | */ | |
41 | private $isBuilt = FALSE; | |
42 | ||
43 | /** | |
44 | * @var array(string) | |
45 | */ | |
46 | private $allModules = NULL; | |
47 | ||
48 | /** | |
49 | * @var array(string) | |
50 | */ | |
51 | private $civiModules = NULL; | |
52 | ||
53 | /** | |
54 | * @var array(string) | |
55 | */ | |
56 | private $drupalModules = NULL; | |
57 | ||
58 | function invoke($numParams, | |
59 | &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, | |
60 | $fnSuffix | |
61 | ) { | |
62 | ||
63 | $this->buildModuleList(); | |
64 | ||
65 | return $this->runHooks($this->allModules, $fnSuffix, | |
66 | $numParams, $arg1, $arg2, $arg3, $arg4, $arg5 | |
67 | ); | |
68 | } | |
69 | ||
70 | /** | |
71 | * Get a list of modules implementing the given hook. | |
72 | * @return Array of module names. | |
73 | */ | |
74 | function moduleImplements($hook_name) { | |
75 | $return = array(); | |
76 | ||
77 | $this->buildModuleList(); | |
78 | ||
79 | // For each module, check if it defines a hook implementation. | |
80 | foreach ($this->allModules as $module) { | |
81 | $fnName = "{$module}_{$hook_name}"; | |
82 | if (function_exists($fnName)) { | |
83 | $return[] = $module; | |
84 | } | |
85 | } | |
86 | return $return; | |
87 | } | |
88 | ||
89 | /** | |
90 | * Build the list of modules to be processed for hooks. | |
91 | */ | |
92 | function buildModuleList() { | |
93 | if ($this->isBuilt === FALSE) { | |
94 | if ($this->drupalModules === NULL) { | |
95 | if (function_exists('module_list')) { | |
96 | // copied from user_module_invoke | |
97 | $this->drupalModules = module_list(); | |
98 | } | |
99 | } | |
100 | ||
101 | if ($this->civiModules === NULL) { | |
102 | $this->civiModules = array(); | |
103 | $this->requireCiviModules($this->civiModules); | |
104 | } | |
105 | ||
106 | $this->allModules = array_merge((array)$this->drupalModules, (array)$this->civiModules); | |
107 | if ($this->drupalModules !== NULL && $this->civiModules !== NULL) { | |
108 | // both CRM and CMS have bootstrapped, so this is the final list | |
109 | $this->isBuilt = TRUE; | |
110 | } | |
111 | } | |
112 | } | |
113 | } | |
114 | ||
115 | ||
116 |