Skip to content

Commit

Permalink
Merge pull request #2521 from yajra/closure-di
Browse files Browse the repository at this point in the history
[9.x] Add support for dependency injection when using closure.

(cherry picked from commit 3e6846a)
  • Loading branch information
yajra committed Jun 21, 2022
1 parent e703d86 commit bf18cfe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Utilities/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ public static function compileContent($content, array $data, array|object $param
{
if (is_string($content)) {
return static::compileBlade($content, static::getMixedValue($data, $param));
} elseif (is_callable($content)) {
}

if (is_callable($content)) {
$reflection = new \ReflectionFunction($content);
$arguments = $reflection->getParameters();

if (count($arguments) > 0) {
return app()->call($content, [$arguments[0]->name => $param]);
}

return $content($param);
}

Expand Down

0 comments on commit bf18cfe

Please sign in to comment.