thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
532 stars 72 forks source link

Add addCallback() method #474

Open jesse-r-s-hines opened 3 years ago

jesse-r-s-hines commented 3 years ago

setCallback() replaces previous callbacks making you have to repeat any logic in the "base case' definition callback if you have a callback on one of the groups. This commit adds an addCallback() method which can be used to add a callback while still letting earlier callbacks be called as well.

addCallback() will add the callback to a stack, and then all of the callbacks will be called when creating the object. If any of the callbacks return false the model won't be persisted a second time.

Calling setCallback() after addCallback() will clear the callback stack before it sets the new callback. This will maintain backwards compatibility with the previous behavior of setCallback().