From 079d7bf47148f1ce24bb95373d7d2bd3b8570a93 Mon Sep 17 00:00:00 2001 From: Mikhail Stupalov Date: Thu, 22 Oct 2026 11:39:39 +0200 Subject: [PATCH] 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 --- flight/core/Dispatcher.php | 4 ++++ tests/DispatcherTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 53f193fc..2e21c867 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -299,6 +299,10 @@ public function execute($callback, array $params = []) $this->verifyValidFunction($callback); if (is_string($callback)) { + if (function_exists($callback)) { + return $callback(...$params); + } + $callback = $this->parseStringClassAndMethod($callback); } diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index af8569ec..be6a04d9 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -168,6 +168,11 @@ public function testInvalidCallableString(): void $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 {