Merge pull request #730 from stupalov/fix/dispatcher-function-name-string

fix: allow plain function name callbacks in Dispatcher::execute()
master
n0nag0n 4 days ago committed by GitHub
commit ca330bca30
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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

@ -168,6 +168,11 @@ class DispatcherTest extends TestCase
$this->dispatcher->execute('nonexistentGlobalFunction'); $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 // It will be useful for executing instance Controller methods statically
public function testCanExecuteAnNonStaticMethodStatically(): void public function testCanExecuteAnNonStaticMethodStatically(): void
{ {

Loading…
Cancel
Save