zumba/swivel

Add support for executing protected / private methods on object

Closed this issue · 1 comments

jonyo commented

A lot of times, it makes most sense to have a behavior method as private or protected method on the object. But doing this will not work currently as it would not be callable within the swivel behavior context.

Use a Closure::bindTo() to allow running a method in the same context as the object, so can allow using something like this:

$manager->forFeature('feature')
->addBehavior('behavior', [$this, 'protectedMethod'], [$args])
// ...
->execute();

Where protectedMethod is a protected method on the object.

Resolved by #24