summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoricewind1991 <icewind1991@gmail.com>2013-07-10 10:38:28 -0700
committericewind1991 <icewind1991@gmail.com>2013-07-10 10:38:28 -0700
commitd134ba9a82a904ba317d4a6d9a75e46ab9249ddc (patch)
tree2ffada42661f96e0e5413af29ca21d3b77d25c89 /lib
parente2a5af4b9edb5cc15285c747e739ec1d58220613 (diff)
parent4a4e139c8391986ce54585f3292f3c2e40dd624d (diff)
downloadnextcloud-server-d134ba9a82a904ba317d4a6d9a75e46ab9249ddc.tar.gz
nextcloud-server-d134ba9a82a904ba317d4a6d9a75e46ab9249ddc.zip
Merge pull request #3978 from owncloud/forwarding-emitter
add forwarding emitter for agregating multiple emitters
Diffstat (limited to 'lib')
-rw-r--r--lib/hooks/basicemitter.php2
-rw-r--r--lib/hooks/forwardingemitter.php50
2 files changed, 51 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
new file mode 100644
index 00000000000..1aacc4012e0
--- /dev/null
+++ b/lib/hooks/forwardingemitter.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\Hooks;
+
+/**
+ * Class ForwardingEmitter
+ *
+ * allows forwarding all listen calls to other emitters
+ *
+ * @package OC\Hooks
+ */
+abstract class ForwardingEmitter extends BasicEmitter {
+ /**
+ * @var \OC\Hooks\Emitter[] array
+ */
+ private $forwardEmitters = array();
+
+ /**
+ * @param string $scope
+ * @param string $method
+ * @param callable $callback
+ */
+ public function listen($scope, $method, $callback) {
+ parent::listen($scope, $method, $callback);
+ foreach ($this->forwardEmitters as $emitter) {
+ $emitter->listen($scope, $method, $callback);
+ }
+ }
+
+ /**
+ * @param \OC\Hooks\Emitter $emitter
+ */
+ 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);
+ }
+ }
+ }
+}