tormjens / eventy

WordPress-like actions and filters for Laravel
422 stars 48 forks source link

Hashable callbacks #17

Closed tormjens closed 5 years ago

tormjens commented 5 years ago

This PR enables callbacks to be compared by signature so they can be removed later on.

Previously there was no convenient way of removing a listener defined as a closure. This PR solves this by hashing callbacks that are of type Closure/anonymous function.

Say you add a callback as such:

Eventy::addAction('foo', function() { echo 'bar'; });

You can now remove it by passing the exact same callback:

Eventy::removeAction('foo', function() { echo 'bar'; });

Should resolve #16