Skip to content

Commit 9e30fd2

Browse files
fix: Correctly handle invokable class tool handlers
1 parent fffaab3 commit 9e30fd2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Elements/RegisteredElement.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ public function __construct(
3333
public function handle(ContainerInterface $container, array $arguments): mixed
3434
{
3535
if (is_string($this->handler)) {
36-
$reflection = new \ReflectionFunction($this->handler);
37-
$arguments = $this->prepareArguments($reflection, $arguments);
38-
$instance = $container->get($this->handler);
39-
return call_user_func($instance, ...$arguments);
36+
if (class_exists($this->handler) && method_exists($this->handler, '__invoke')) {
37+
$reflection = new \ReflectionMethod($this->handler, '__invoke');
38+
$arguments = $this->prepareArguments($reflection, $arguments);
39+
$instance = $container->get($this->handler);
40+
return call_user_func($instance, ...$arguments);
41+
}
42+
43+
if (function_exists($this->handler)) {
44+
$reflection = new \ReflectionFunction($this->handler);
45+
$arguments = $this->prepareArguments($reflection, $arguments);
46+
return call_user_func($this->handler, ...$arguments);
47+
}
4048
}
4149

4250
if (is_callable($this->handler)) {

0 commit comments

Comments
 (0)