-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Hi
Just an idea: transformers currently have 2 ways to be injected:
- using a dedicated class and an
API::transformcall - by implementing
Dingo\Api\Transformer\TransformableInterfacein the model
In my opinion the second option is more clean as I this seems to me like some sort of model definition similar to getAttribute().
However, how about defining the implementation as a trait? This avoids collision when a model needs multiple interfaces. (Actually I think packages never should define interfaces for models just for this reason)
Some code suggestions:
Change Dingo\API\Transformer\TransformableInterface to Dingo\API\Transformer\TransformableTrait:
trait TransformableTrait {
/**
* Get the transformer instance.
* Should be overridden in the implementing class.
*
* @return mixed
*/
public function getTransformer() {
return array();
}
}
In Dingo\API\Transformer\Factory:
/**
* Determine if the class is bound by the transformable contract.
*
* @param string|object $class
* @return bool
*/
protected function boundByContract($class)
{
return is_object($class) and in_array('TransformableTrait', class_uses($class));
}
Metadata
Metadata
Assignees
Labels
No labels