Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
225
Merge Requests
225
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
da662429
Commit
da662429
authored
Jun 05, 2016
by
catch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2682373
by klausi, thePanz: Implement ContainerAwareEventDispatcher::getListenerPriority()
parent
3c7e318e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
...mponent/EventDispatcher/ContainerAwareEventDispatcher.php
+29
-0
core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
...ent/EventDispatcher/ContainerAwareEventDispatcherTest.php
+17
-3
No files found.
core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
View file @
da662429
...
...
@@ -156,6 +156,35 @@ public function getListeners($event_name = NULL) {
return
$result
;
}
/**
* {@inheritdoc}
*/
public
function
getListenerPriority
(
$eventName
,
$listener
)
{
// Parts copied from \Symfony\Component\EventDispatcher, that's why you see
// a yoda condition here.
if
(
!
isset
(
$this
->
listeners
[
$eventName
]))
{
return
;
}
foreach
(
$this
->
listeners
[
$eventName
]
as
$priority
=>
$listeners
)
{
if
(
FALSE
!==
(
$key
=
array_search
([
'callable'
=>
$listener
],
$listeners
,
TRUE
)))
{
return
$priority
;
}
}
// Resolve service definitions if the listener has not been found so far.
foreach
(
$this
->
listeners
[
$eventName
]
as
$priority
=>
&
$definitions
)
{
foreach
(
$definitions
as
$key
=>
&
$definition
)
{
if
(
!
isset
(
$definition
[
'callable'
]))
{
// Once the callable is retrieved we keep it for subsequent method
// invocations on this class.
$definition
[
'callable'
]
=
[
$this
->
container
->
get
(
$definition
[
'service'
][
0
]),
$definition
[
'service'
][
1
]];
if
(
$definition
[
'callable'
]
===
$listener
)
{
return
$priority
;
}
}
}
}
}
/**
* {@inheritdoc}
*/
...
...
core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
View file @
da662429
...
...
@@ -172,10 +172,24 @@ public function testRemoveService()
$this
->
assertTrue
(
$otherService
->
preFooInvoked
);
}
public
function
testGetListenerPriority
()
public
function
testGetListenerPriority
WithServices
()
{
// Override the parent test as our implementation doesn't define
// getListenerPriority().
$container
=
new
ContainerBuilder
();
$container
->
register
(
'listener_service'
,
TestEventListener
::
class
);
$listeners
=
array
(
'test_event'
=>
array
(
5
=>
array
(
array
(
'service'
=>
array
(
'listener_service'
,
'preFoo'
)),
),
),
);
$dispatcher
=
new
ContainerAwareEventDispatcher
(
$container
,
$listeners
);
$listenerService
=
$container
->
get
(
'listener_service'
);
$actualPriority
=
$dispatcher
->
getListenerPriority
(
'test_event'
,
[
$listenerService
,
'preFoo'
]);
$this
->
assertSame
(
5
,
$actualPriority
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment