-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Implementing and re-utilizing an abstract aggregate listener #3876
Implementing and re-utilizing an abstract aggregate listener #3876
Conversation
use Zend\EventManager\StaticEventManager; | ||
use Zend\Stdlib\CallbackHandler; | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this stuff still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only @group
I agree with to have a common superclass for *Listener classes. But I don't see the same for other classes that mainly aren't listeners (Plugin, Strategy, etc) |
@Maks3w all changed classes were previously implementing the interface: no kittens were harmed in this PR :) Actually: nvm... let's see what @marc-mabe has to say on the change on the abstract plugin for the cache... |
Abstract class is not a replacement of the interface. If it is then the interface can be removed. I see the interfaces as features of a class and hierarchy as the natural classification |
In fact I am not replacing the interface. The interface stays there and I'm fine with it: the repeated code goes away. I am adding one class in the inheritance, not pushing any contract out of it :) |
@Ocramius: the abstract class is a good way removing duplicate code but why you removed grouping callback handles by |
@marc-mabe the fact is that (and that's a personal thought) following is perfectly valid: <?php
$listener = new AggregateStuff();
$evm->attach($listener);
$evm->attach($listener); // second time (simply triggers the listener 2 times...)
// etc
$evm->detach($listener);
$evm->detach($listener); // even if it was already detached - code is simply noop I removed grouping because
|
@Ocramius For your example attaching a listener twice to be called twice is ok but on detaching it only one of the listener should be detached if it was attached twice. Because grouping the following should work: $excaptionHandler = new Zend\Cache\Storage\Plugin\ExceptionHandler();
$apcCache->addPlugin($excaptionHandler);
$memCache->addPlugin($excaptionHandler);
// exceptions should be catched by both caches
$apcCache->removePlugin($excaptionHandler);
// exceptions should be catched only by $memCache |
@marc-mabe |
@Ocramius If that's the case i missed something and all is valid 👍 |
public function testDetach() | ||
{ | ||
$eventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); | ||
$unrelatedEventManager = $this->getMock('Zend\\EventManager\\EventManagerInterface'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-mabe this is the example where I show that unrelated event managers don't cause event listeners to be detached (FYI)
Only one comment and request, @Ocramius : also create a PHP 5.4 trait that mimics what Scheduling for 2.2.0. |
@Ocramius Since abstract public function attach(EventManagerInterface $events); right? |
It's inherited from the interface, no need to re-define it Marco Pivetta On 22 March 2013 02:31, Daniel Gimenes [email protected] wrote:
|
/** | ||
* @var \Zend\Stdlib\CallbackHandler[] | ||
*/ | ||
protected $callbacks = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call this "listeners", not "callbacks". I can change that on merge, though.
…dlers in aggregates
…tener Implementing and re-utilizing an abstract aggregate listener
Merged! |
…ture/abstract-aggregate-listener Implementing and re-utilizing an abstract aggregate listener
- EOF ending
…ture/abstract-aggregate-listener Implementing and re-utilizing an abstract aggregate listener
…ture/abstract-aggregate-listener Implementing and re-utilizing an abstract aggregate listener
- EOF ending
…ture/abstract-aggregate-listener Implementing and re-utilizing an abstract aggregate listener
…ture/abstract-aggregate-listener Implementing and re-utilizing an abstract aggregate listener
As of #3874, I abstracted the duplicate logic of the aggregate listener into an abstract class.
This abstract aggregate listener only defines the logic for
detach
. Developing something related toattach
would increase the method calls within the framework by quite a bit, so I preferred leaving that part of the implementation to the end-user.This PR introduces minor BCs that should be discussed first:
attach
(nowvoid
)detach
(nowvoid
)listeners
tocallbacks
(maybecallbackHandlers
? let me know...)Zend\Cache\Storage\Plugin\AbstractPlugin
now inheriting an additional abstract method (this breaks eventual plugins extending it)Zend\Cache
don't throw exceptions anymore if the listener is attached multiple timesZend\Cache
don't throw exceptions anymore if the listener is detached and was never attachedPing @marc-mabe