Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
925d09cb
Commit
925d09cb
authored
11 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
add forwarding emitter for agregating multiple emitters
parent
8d8f99fb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/hooks/forwardingemitter.php
+42
-0
42 additions, 0 deletions
lib/hooks/forwardingemitter.php
tests/lib/hooks/forwardingemitter.php
+62
-0
62 additions, 0 deletions
tests/lib/hooks/forwardingemitter.php
with
104 additions
and
0 deletions
lib/hooks/forwardingemitter.php
0 → 100644
+
42
−
0
View file @
925d09cb
<?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
;
}
}
This diff is collapsed.
Click to expand it.
tests/lib/hooks/forwardingemitter.php
0 → 100644
+
62
−
0
View file @
925d09cb
<?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
Test\Hooks
;
use
OC\Hooks\PublicEmitter
;
class
DummyForwardingEmitter
extends
\OC\Hooks\ForwardingEmitter
{
public
function
emitEvent
(
$scope
,
$method
,
$arguments
=
array
())
{
$this
->
emit
(
$scope
,
$method
,
$arguments
);
}
/**
* @param \OC\Hooks\Emitter $emitter
*/
public
function
forward
(
$emitter
)
{
parent
::
forward
(
$emitter
);
}
}
/**
* Class ForwardingEmitter
*
* allows forwarding all listen calls to other emitters
*
* @package OC\Hooks
*/
class
ForwardingEmitter
extends
BasicEmitter
{
public
function
testSingleForward
()
{
$baseEmitter
=
new
PublicEmitter
();
$forwardingEmitter
=
new
DummyForwardingEmitter
();
$forwardingEmitter
->
forward
(
$baseEmitter
);
$hookCalled
=
false
;
$forwardingEmitter
->
listen
(
'Test'
,
'test'
,
function
()
use
(
&
$hookCalled
)
{
$hookCalled
=
true
;
});
$baseEmitter
->
emit
(
'Test'
,
'test'
);
$this
->
assertTrue
(
$hookCalled
);
}
public
function
testMultipleForwards
()
{
$baseEmitter1
=
new
PublicEmitter
();
$baseEmitter2
=
new
PublicEmitter
();
$forwardingEmitter
=
new
DummyForwardingEmitter
();
$forwardingEmitter
->
forward
(
$baseEmitter1
);
$forwardingEmitter
->
forward
(
$baseEmitter2
);
$hookCalled
=
0
;
$forwardingEmitter
->
listen
(
'Test'
,
'test1'
,
function
()
use
(
&
$hookCalled
)
{
$hookCalled
++
;
});
$forwardingEmitter
->
listen
(
'Test'
,
'test2'
,
function
()
use
(
&
$hookCalled
)
{
$hookCalled
++
;
});
$baseEmitter1
->
emit
(
'Test'
,
'test1'
);
$baseEmitter1
->
emit
(
'Test'
,
'test2'
);
$this
->
assertEquals
(
2
,
$hookCalled
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment