Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 2446145

Browse files
committed
feat: Creates PrioritizedListenerAttachmentInterface
This provides the methods necessary for attaching listeners. It does not extend PrioritizedListenerProviderInterface, as we want to be able to re-use that particular interface with shared providers, which will have a different attachment mechanism in version 3 releases.
1 parent 092b8e3 commit 2446145

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

TODO-PSR-14.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
- [x] Create a `PrioritizedListenerProvider` interface extending the
1616
`ListenerProviderInterface` and defining a
1717
`getListenersForEventByPriority($event, array $identifiers = []) : array<int, callable[]>` method.
18-
- [ ] Create a `PrioritizedListenerAttachmentInterface`, defining:
19-
- [ ] `attach($event, callable $listener, $priority = 1)` (where `$event`
18+
- [x] Create a `PrioritizedListenerAttachmentInterface`, defining:
19+
- [x] `attach($event, callable $listener, $priority = 1)` (where `$event`
2020
can be an object or string name)
21-
- [ ] `detach(callable $listener, $event = null, $force = false)` (where `$event`
21+
- [x] `detach(callable $listener, $event = null, $force = false)` (where `$event`
2222
can be an object or string name and `$force` is boolean)
23-
- [ ] `attachWildcardListener(callable $listener, $priority = 1)`
23+
- [x] `attachWildcardListener(callable $listener, $priority = 1)`
2424
(`attach('*', $listener, $priority)` will proxy to this method)
25+
- [x] `detachWildcardListener(callable $listener, $force = false)`
26+
(`detach($listener, '*', $force)` will proxy to this method)
27+
- [x] `clearListeners($event)`
2528
- [ ] Create a `PrioritizedListenerProvider` implementation of the above based
2629
on the internals of `EventManager`
2730
- [ ] attachment/detachment
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-eventmanager for the canonical source repository
4+
* @copyright Copyright (c) 2019 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace Zend\EventManager\ListenerProvider;
9+
10+
interface PrioritizedListenerAttachmentInterface
11+
{
12+
/**
13+
* @param string $event The event type to which the listener will respond.
14+
* @param callable $listener The listener itself.
15+
* @param int $priority The priority at which to attach the listener. High
16+
* priorities respond earlier; negative priorities respond later.
17+
* @return void
18+
*/
19+
public function attach($event, callable $listener, $priority = 1);
20+
21+
/**
22+
* @param callable $listener The listener to detach.
23+
* @param null|string $event Which events to detach the listener from.
24+
* When null, all events. If '*', this will only detach the wildcard
25+
* entry for a listener, unless $force is true.
26+
* @return void
27+
*/
28+
public function detach(callable $listener, $event = null);
29+
30+
/**
31+
* Attaches a listener as a wildcard listener (to all events).
32+
*
33+
* Analagous to:
34+
*
35+
* <code>
36+
* attach('*', $listener, $priority)
37+
* </code>
38+
*
39+
* The above will actually invoke this method instead.
40+
*
41+
* @param callable $listener The listener to attach.
42+
* @param int $priority The priority at which to attach the listener.
43+
* High priorities respond earlier; negative priorities respond later.
44+
* @return void
45+
*/
46+
public function attachWildcardListener(callable $listener, $priority = 1);
47+
48+
/**
49+
* Detaches a wildcard listener.
50+
*
51+
* Analagous to:
52+
*
53+
* <code>
54+
* detach($listener, '*', $force)
55+
* </code>
56+
*
57+
* The above will actually invoke this method instead.
58+
*
59+
* @param callable $listener The listener to detach.
60+
* @return void
61+
*/
62+
public function detachWildcardListener(callable $listener);
63+
64+
/**
65+
* @param string $event The event for which to remove listeners.
66+
* @return void
67+
*/
68+
public function clearListeners($event);
69+
}

0 commit comments

Comments
 (0)