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
4a4e139c
Commit
4a4e139c
authored
11 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
forward previously registerd hooks
parent
925d09cb
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/hooks/basicemitter.php
+1
-1
1 addition, 1 deletion
lib/hooks/basicemitter.php
lib/hooks/forwardingemitter.php
+8
-0
8 additions, 0 deletions
lib/hooks/forwardingemitter.php
tests/lib/hooks/forwardingemitter.php
+12
-0
12 additions, 0 deletions
tests/lib/hooks/forwardingemitter.php
with
21 additions
and
1 deletion
lib/hooks/basicemitter.php
+
1
−
1
View file @
4a4e139c
...
...
@@ -13,7 +13,7 @@ abstract class BasicEmitter implements Emitter {
/**
* @var (callable[])[] $listeners
*/
pr
ivate
$listeners
=
array
();
pr
otected
$listeners
=
array
();
/**
* @param string $scope
...
...
This diff is collapsed.
Click to expand it.
lib/hooks/forwardingemitter.php
+
8
−
0
View file @
4a4e139c
...
...
@@ -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
);
}
}
}
}
This diff is collapsed.
Click to expand it.
tests/lib/hooks/forwardingemitter.php
+
12
−
0
View file @
4a4e139c
...
...
@@ -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
);
}
}
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