thephpleague / factory-muffin

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

Hydration Strategies #434

Open nagibyro opened 7 years ago

nagibyro commented 7 years ago

Looking at the attribute generate method it looks like there is only support for setter injection. It would be nice to be able to customize hydration for different types of objects -- such as immutable objects whose attributes are only set through the constructor. Perhaps creating a hydrationStrategyInterface or something of that nature. This would allow others to create strategies that work better with their objects such as using reflection to set attributes instead.

floriandammeyer commented 6 years ago

Sadly this idea has not received any feedback yet. I would really appreciate being able to change the way attributes are set on a new instance. We employ domain-driven design and instead of implementing a bunch of otherwise meaningless setters, we use more semantically named methods to update an instance's attributes. And for value objects, which are immutable, we don't implement any setters at all, so FactoryMuffin would have to use a reflection based strategy or the constructor to set attributes.