CiviEventInspector
in package
Class CiviEventInspector
The event inspector is a development tool which provides metadata about events. It can be used for code-generators and documentation-generators.
$i = new CiviEventInspector();
print_r(CRM_Utils_Array::collect('name', $i->getAll()));
An event definition includes these fields:
- type: string, required. Ex: 'hook' or 'object'
- name: string, required. Ex: 'hook_civicrm_post' or 'civi.dao.postInsert'
- class: string, required. Ex: 'Civi\Core\Event\GenericHookEvent'.
- signature: string, required FOR HOOKS. Ex: '$first, &$second'.
- fields: array, required FOR HOOKS. List of hook parameters.
- stub: ReflectionMethod, optional. An example function with docblocks/inputs.
Note: The inspector is only designed for use in developer workflows, such as code-generation and inspection. It should be not called by regular runtime logic.
Table of Contents
Properties
- $eventDefs : array<string|int, mixed>
Methods
- add() : CiviEventInspector
- Add a new event definition.
- addEventClass() : CiviEventInspector
- Scan a Symfony event class for metadata, and add it.
- addStaticStubs() : CiviEventInspector
- Scan a class for hook stubs, and add all of them.
- build() : CiviEventInspector
- Perform a scan to identify/describe all events.
- find() : array<string|int, mixed>
- Find any events that match a pattern.
- findBuiltInEvents() : mixed
- Register the default hooks defined by 'CRM_Utils_Hook'.
- get() : array<string|int, mixed>
- Get the definition of one event.
- getAll() : array<string|int, mixed>
- Get a list of all events.
- validate() : bool
Properties
$eventDefs
protected
array<string|int, mixed>
$eventDefs
Array(string $name => array $eventDef).
Ex: $eventDefs['hook_civicrm_foo']['description_html'] = 'Hello world';
Methods
add()
Add a new event definition.
public
add(array<string|int, mixed> $eventDef) : CiviEventInspector
Parameters
- $eventDef : array<string|int, mixed>
Return values
CiviEventInspectoraddEventClass()
Scan a Symfony event class for metadata, and add it.
public
addEventClass(string $event, string $className) : CiviEventInspector
Parameters
- $event : string
-
Ex: 'civi.api.authorize'.
- $className : string
-
Ex: 'Civi\API\Event\AuthorizeEvent'.
Return values
CiviEventInspectoraddStaticStubs()
Scan a class for hook stubs, and add all of them.
public
addStaticStubs(string $className, string $prefix[, null|callable $filter = NULL ]) : CiviEventInspector
Parameters
- $className : string
-
The name of a class which contains static stub functions. Ex: 'CRM_Utils_Hook'.
- $prefix : string
-
A prefix to apply to all hook names. Ex: 'hook_civicrm_'.
- $filter : null|callable = NULL
-
An optional function to filter/rewrite the metadata for each hook.
Return values
CiviEventInspectorbuild()
Perform a scan to identify/describe all events.
public
build([bool $force = FALSE ]) : CiviEventInspector
Parameters
- $force : bool = FALSE
Return values
CiviEventInspectorfind()
Find any events that match a pattern.
public
find(string $regex) : array<string|int, mixed>
Parameters
- $regex : string
Return values
array<string|int, mixed> —Array(string $name => array $eventDef). Ex: $result['hook_civicrm_foo']['description_html'] = 'Hello world';
findBuiltInEvents()
Register the default hooks defined by 'CRM_Utils_Hook'.
public
static findBuiltInEvents(GenericHookEvent $e) : mixed
Parameters
- $e : GenericHookEvent
Tags
get()
Get the definition of one event.
public
get(string $name) : array<string|int, mixed>
Parameters
- $name : string
-
Ex: 'hook_civicrm_alterSettingsMetaData'.
Return values
array<string|int, mixed> —Ex: $result['description_html'] = 'Hello world';
getAll()
Get a list of all events.
public
getAll() : array<string|int, mixed>
Return values
array<string|int, mixed> —Array(string $name => array $eventDef). Ex: $result['hook_civicrm_foo']['description_html'] = 'Hello world';
validate()
public
validate(mixed $eventDef) : bool
Parameters
- $eventDef : mixed
Return values
bool —TRUE if valid.