/** * Calls a method with given arguments * * @param string $methodName * @param array $arguments * @return mixed * @throws FunctionException If the method does not exist */ public function call($methodName, $arguments = []) { $methodName = strtolower($methodName); if (isset($this->aliases[$methodName])) { $methodName = $this->aliases[$methodName]; } if (isset($this->functions[$methodName])) { $arguments = $this->prepareArguments($arguments); if ($this->functions[$methodName] === true) { // built in function return call_user_func_array([$this, $methodName], $arguments); } else { // this is a external callable // provide access to function registry (pass as first parameter) array_unshift($arguments, $this); return call_user_func_array($this->functions[$methodName], $arguments); } } else { if ($this->parent) { return $this->parent->call($methodName, $arguments); } } }
/** * @covers addFunction */ public function testCustomFunction() { $registry = new FunctionRegistry(); $registry->addFunction('foobar', [$this, 'foobarCallable']); $registry->call('foobar', ['a', 'b']); }