fix: allow plain function name callbacks in Dispatcher::execute()

Since v3.19.2 every string callback went through parseStringClassAndMethod(),
so routes and events mapped to a global function name threw
InvalidArgumentException. Call existing functions directly and keep the
Class->method / Class::method parsing as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pull/730/head
Mikhail Stupalov 6 days ago
parent 06f10a7eb1
commit 079d7bf471

@ -299,6 +299,10 @@ class Dispatcher
$this->verifyValidFunction($callback);
if (is_string($callback)) {
if (function_exists($callback)) {
return $callback(...$params);
}
$callback = $this->parseStringClassAndMethod($callback);
}

@ -168,6 +168,11 @@ class DispatcherTest extends TestCase
$this->dispatcher->execute('nonexistentGlobalFunction');
}
public function testExecuteGlobalFunctionString(): void
{
$this->assertSame('HELLO', $this->dispatcher->execute('strtoupper', ['hello']));
}
// It will be useful for executing instance Controller methods statically
public function testCanExecuteAnNonStaticMethodStatically(): void
{

Loading…
Cancel
Save