Skip to content

Delegation and Type-Hinted Hydrators

Choose a tag to compare

@Rican7 Rican7 released this 04 Apr 05:52
· 65 commits to master since this release

This release adds a new AbstractDelegateHydrator abstract hydration class that allows for the hydration to be delegated to a callback or other callable. By default, a named method is attempted to be found, but any callable could be returned through overrides.

This enables a lot of interesting uses, most notably this allows hydrators to be created that have strongly type-hinted hydration arguments while still perfectly satisfying the HydratorInterface. Essentially this allows the bypassing of the type variance rules enforced by PHP in a way that provides a generics-like definition. Ultimately, if/when PHP gets generics this will no longer be necessary, as one could simply implement a hydrator using typed arguments like: HydratorInterface<IncomingDataType, ModelType>.

This feature was born out of a frustration with being unable to properly implement the HydratorInterface in an application I was using Incoming in without dropping the type hints:

4-1-2015-12-09-18-am-b5b0