Skip to content

Commit 68ac046

Browse files
committed
Allow a closure or an adapter instance when setting the transformation layer at runtime.
Signed-off-by: Jason Lewis <[email protected]>
1 parent 1dfcbe2 commit 68ac046

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Transformer/Factory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,16 @@ public function getTransformerBindings()
192192
/**
193193
* Set the transformation layer at runtime.
194194
*
195-
* @param \Dingo\Api\Contract\Transformer\Adapter $transformer
195+
* @param \Closure|\Dingo\Api\Contract\Transformer\Adapter $transformer
196196
*
197197
* @return void
198198
*/
199-
public function setTransformer(Adapter $transformer)
199+
public function setTransformer($transformer)
200200
{
201+
if (is_callable($transformer)) {
202+
$transformer = call_user_func($transformer, $this->container);
203+
}
204+
201205
$this->transformer = $transformer;
202206
}
203207
}

0 commit comments

Comments
 (0)