Skip to content

Commit

Permalink
Use Civi Event Inspector to detect hooks. Refs #6, #8.
Browse files Browse the repository at this point in the history
Use \Civi\Core\CiviEventInspector() to identify events, hooks.

This is based on civicrm/civicrm-core#10161 which is WIP currently.

Refs #6, #8.
Refs civicrm/civicrm-core#10161.
  • Loading branch information
xurizaemon committed Apr 14, 2017
1 parent 6afdb81 commit 704735d
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions showallthehooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,28 @@
* @return array of ReflectionClass objects.
*/
function _showallthehooks_list_hooks() {
$class = new ReflectionClass('CRM_Utils_Hook');
$hooks = $class->getMethods(ReflectionMethod::IS_STATIC);
$ignore = ['singleton'];
sort($hooks);
$hooks = array_filter($hooks, function($m) use ($ignore) {
if (isset($m->name) && !in_array($m->name, $ignore)) {
return true;
if (class_exists('Civi\Core\CiviEventInspector')) {
// Event Inspector is available from PR10161 onwards.
// https://github.com/civicrm/civicrm-core/pull/10161
$hooks = [];
$inspector = new \Civi\Core\CiviEventInspector();
$allHooks = $inspector->getAll();
foreach ($allHooks as $hook) {
if (isset($hook['stub'])) {
$hooks[] = $hook;
}
}
});
}
else {
$class = new ReflectionClass('CRM_Utils_Hook');
$hooks = $class->getMethods(ReflectionMethod::IS_STATIC);
$ignore = ['singleton'];
$hooks = array_filter($hooks, function($m) use ($ignore) {
if (isset($m->name) && !in_array($m->name, $ignore)) {
return TRUE;
}
});
}
return $hooks;
}

Expand Down

0 comments on commit 704735d

Please sign in to comment.