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 {