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

dev/core#1460 - Small cleanups in CiviEventDispatcher{,Test} #17216

Merged
merged 2 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Civi/Core/CiviEventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,22 @@ class CiviEventDispatcher extends ContainerAwareEventDispatcher {
private $autoListeners = [];

/**
* A list of dispatch-policies (based on an exact-match to the event name).
*
* Note: $dispatchPolicyExact and $dispatchPolicyRegex should coexist; e.g.
* if one is NULL, then both are NULL. If one is an array, then both are arrays.
*
* @var array|null
* Array(string $eventName => string $action)
*/
private $dispatchPolicyExact = NULL;

/**
* A list of dispatch-policies (based on an regex-match to the event name).
*
* Note: $dispatchPolicyExact and $dispatchPolicyRegex should coexist; e.g.
* if one is NULL, then both are NULL. If one is an array, then both are arrays.
*
* @var array|null
* Array(string $eventRegex => string $action)
*/
Expand Down Expand Up @@ -155,6 +165,8 @@ public static function delegateToUF($event, $eventName) {
}

/**
* Attach any pattern-based listeners which may be interested in $eventName.
*
* @param string $eventName
* Ex: 'civi.api.resolve' or 'hook_civicrm_dashboard'.
*/
Expand All @@ -174,7 +186,7 @@ protected function bindPatterns($eventName) {
}

/**
* The dispatch policy allows you to filter certain events.
* Set the dispatch policy. This allows you to filter certain events.
* This can be useful during upgrades or debugging.
*
* Enforcement will add systemic overhead, so this should normally be NULL.
Expand Down Expand Up @@ -219,7 +231,10 @@ public function setDispatchPolicy($dispatchPolicy) {
// }

/**
* Determine whether the dispatch policy applies to a given event.
*
* @param string $eventName
* Ex: 'civi.api.resolve' or 'hook_civicrm_dashboard'.
* @return string
* Ex: 'run', 'drop', 'fail'
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/Civi/Core/CiviEventDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testDispatchPolicy_run() {
$d->addListener('hook_civicrm_fakeRunnable', function() use (&$calls) {
$calls['hook_civicrm_fakeRunnable'] = 1;
});
$d->dispatch('hook_civicrm_fakeRunnable', new GenericHookEvent());
$d->dispatch('hook_civicrm_fakeRunnable', GenericHookEvent::create([]));
$this->assertEquals(1, $calls['hook_civicrm_fakeRunnable']);
}

Expand All @@ -33,7 +33,7 @@ public function testDispatchPolicy_drop() {
$d->addListener('hook_civicrm_fakeDroppable', function() use (&$calls) {
$calls['hook_civicrm_fakeDroppable'] = 1;
});
$d->dispatch('hook_civicrm_fakeDroppable', new GenericHookEvent());
$d->dispatch('hook_civicrm_fakeDroppable', GenericHookEvent::create([]));
$this->assertTrue(!isset($calls['hook_civicrm_fakeDroppable']));
}

Expand All @@ -43,7 +43,7 @@ public function testDispatchPolicy_fail() {
'/^hook_civicrm_fakeFa/' => 'fail',
]);
try {
$d->dispatch('hook_civicrm_fakeFailure', new GenericHookEvent());
$d->dispatch('hook_civicrm_fakeFailure', GenericHookEvent::create([]));
$this->fail('Expected exception');
}
catch (\Exception $e) {
Expand Down