aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/hooks/basicemitter.php2
-rw-r--r--lib/hooks/forwardingemitter.php8
-rw-r--r--tests/lib/hooks/forwardingemitter.php12
3 files changed, 21 insertions, 1 deletions
diff --git a/lib/hooks/basicemitter.php b/lib/hooks/basicemitter.php
index e615a58cfe8..9ffe1af2314 100644
--- a/lib/hooks/basicemitter.php
+++ b/lib/hooks/basicemitter.php
@@ -13,7 +13,7 @@ abstract class BasicEmitter implements Emitter {
/**
* @var (callable[])[] $listeners
*/
- private $listeners = array();
+ protected $listeners = array();
/**
* @param string $scope
diff --git a/lib/hooks/forwardingemitter.php b/lib/hooks/forwardingemitter.php
index 518641ac7cf..1aacc4012e0 100644
--- a/lib/hooks/forwardingemitter.php
+++ b/lib/hooks/forwardingemitter.php
@@ -38,5 +38,13 @@ abstract class ForwardingEmitter extends BasicEmitter {
*/
protected function forward($emitter) {
$this->forwardEmitters[] = $emitter;
+
+ //forward all previously connected hooks
+ foreach ($this->listeners as $key => $listeners) {
+ list($scope, $method) = explode('::', $key, 2);
+ foreach ($listeners as $listener) {
+ $emitter->listen($scope, $method, $listener);
+ }
+ }
}
}
diff --git a/tests/lib/hooks/forwardingemitter.php b/tests/lib/hooks/forwardingemitter.php
index 0686ebece9f..decf6bb354c 100644
--- a/tests/lib/hooks/forwardingemitter.php
+++ b/tests/lib/hooks/forwardingemitter.php
@@ -59,4 +59,16 @@ class ForwardingEmitter extends BasicEmitter {
$baseEmitter1->emit('Test', 'test2');
$this->assertEquals(2, $hookCalled);
}
+
+ public function testForwardExistingHooks() {
+ $baseEmitter = new PublicEmitter();
+ $forwardingEmitter = new DummyForwardingEmitter();
+ $hookCalled = false;
+ $forwardingEmitter->listen('Test', 'test', function () use (&$hookCalled) {
+ $hookCalled = true;
+ });
+ $forwardingEmitter->forward($baseEmitter);
+ $baseEmitter->emit('Test', 'test');
+ $this->assertTrue($hookCalled);
+ }
}