Hello, I think it would be a great idea to use "is_callable" instead of "function_exists" in "phpagi-asmanager.php" in the function "process_event", or just add support for this as well...
For example:
function process_event($parameters) { $ret = false; $e = strtolower($parameters['Event']); $this->log("Got event.. $e"); $handler = ''; if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e]; elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*']; if(function_exists($handler)) { $this->log("Execute handler $handler"); $ret = $handler($e, $parameters, $this->server, $this->port); } else if (is_callable($handler)) { $this->log("Execute handler $handler"); call_user_func_array($handler, array($e, $parameters, $this->server, $this->port)); } else $this->log("No event handler for event '$e'"); return $ret; }
Great idea. To avoid typecasting a callable to a string, you can do the following.
This is also backwardly compatible with the old type of event handler, without needing to use function_exists.
function process_event($parameters) { $ret = false; $e = strtolower($parameters['Event']); $this->log("Got event.. $e"); $handler = ''; if(isset($this->event_handlers[$e])) $handler = $this->event_handlers[$e]; elseif(isset($this->event_handlers['*'])) $handler = $this->event_handlers['*']; if(is_callable($handler)) { $this->log("Execute handler for event '$e'"); call_user_func($handler, $e, $parameters, $this->server, $this->port); } else $this->log("No event handler for event '$e'"); return $ret; }
Log in to post a comment.
For example:
Last edit: Roman Davydov 2013-06-11
Great idea. To avoid typecasting a callable to a string, you can do the following.
This is also backwardly compatible with the old type of event handler, without needing to use function_exists.