Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CiviEventInspector - Add util for displaying hook metadata #10161

Merged
merged 9 commits into from
Apr 20, 2017

Conversation

totten
Copy link
Member

@totten totten commented Apr 14, 2017

This is meant to facilitate better code-generators and documentation-generators. Key features:

  • Adds a new class, Civi\Core\CiviEventInspector.
  • Adds a new hook, hook_civicrm_eventDefs. Extensions may use this to document their hooks.
  • Implements the hook in core (to report on civicrm-core hooks and events)
  • If you follow the practice of declaring static hook stubs (like civicrm-core does), then use addStaticStubs() to assimilate of them.

(Description updated to reflect current class/hook names.)

@totten
Copy link
Member Author

totten commented Apr 14, 2017

On second thought, if the event dispatcher is the canonical representation of hooks, then perhaps I should rename it to EventInspector and include metadata about all events (regardless of whether they're named hook_foo). That's a small number of additional events, but it'd more complete.

@totten
Copy link
Member Author

totten commented Apr 14, 2017

@xurizaemon @JohnFF I've updated this to report all events, including both hooks and oddballs.

To get a list of hooks, you could run:

$ cv ev '$i = new \Civi\Core\CiviEventInspector(); return $i->find("/^hook_/");'
...
   "hook_civicrm_validateForm": {
        "name": "hook_civicrm_validateForm",
        "description_html": "This hook is invoked during all CiviCRM form validation. An array of errors<br />\ndetected is returned. Else we assume validation succeeded.@param string $formName<br />\n&nbsp;&nbsp;&nbsp;&nbsp; The name of the form.<br />\n<strong>Param</strong>: array &amp;$fields the POST parameters as filtered by QF<br />\n<strong>Param</strong>: array &amp;$files the FILES parameters as sent in by POST<br />\n<strong>Param</strong>: array &amp;$form the form object<br />\n<strong>Param</strong>: array &amp;$errors the array of errors.@return mixed<br />\n&nbsp;&nbsp;&nbsp;&nbsp; formRule hooks return a boolean or<br />\n&nbsp;&nbsp;&nbsp;&nbsp;                         an array of error messages which display a QF Error<br />\n&nbsp;&nbsp;&nbsp;&nbsp;*/",
        "fields": {
            "formName": {
                "name": "formName",
                "ref": false
            },
            "fields": {
                "name": "fields",
                "ref": true
            },
            "files": {
                "name": "files",
                "ref": true
            },
            "form": {
                "name": "form",
                "ref": true
            },
            "errors": {
                "name": "errors",
                "ref": true
            }
        },
        "class": "Civi\\Core\\Event\\GenericHookEvent",
        "type": "hook",
        "signature": "$formName, &$fields, &$files, &$form, &$errors"
    },
...

This will make the function more useful for the hook inspector.
This is meant to facilitate better code-generators and
documentation-generators. Key features:

 * Adds a new class, `CRM_Utils_Hook_Inspector`.
 * Adds a new hook, `hook_civicrm_hooks`. Extensions may use this to document their hooks.
 * Implements the hook in core (to report on `civicrm-core` hooks)
 * If you follow the practice of declaring static hook stubs (like
   `civicrm-core` does), then use `addStaticStubs()` to assimilate of them.
// Get rid of comment stars
$text = str_replace(array("\n * ", "\n *\n", "\n */\n", "/**\n"), array("\n", "\n\n", '', ''), $text);
$text = str_replace(array("\n * ", "\n * ", "\n *\n", "\n */\n", "/**\n"), array("\n", "\n\n", '', ''), $text);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, that last bit's a mistake. I'll squash it out.

@totten totten changed the title CRM_Utils_Hook_Inspector - Add util for displaying hook metadata CiviEventInspector - Add util for displaying hook metadata Apr 14, 2017
xurizaemon added a commit to fuzionnz/contrib.showallthehooks that referenced this pull request Apr 14, 2017
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.
@eileenmcnaughton
Copy link
Contributor

@xurizaemon this is out of WIP now & you seem to have some familiarity with it - it looks OK to me - can you confirm you think it is good to merge?

@xurizaemon
Copy link
Member

It seems like it will be relatively safe since nothing of significance is using it. ShowAllTheHooks is using it (see prev commit from fuzionnz/contrib.showallthehooks) but that's hardly an extensive test ... it does work, and it gives an interface that informs for available hooks and events, which is great.

@eileenmcnaughton
Copy link
Contributor

I think given the scope of this I agree with @xurizaemon and am good to merge

@eileenmcnaughton eileenmcnaughton merged commit 6120013 into civicrm:master Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants