好多地方都调用一个类,然后执行该类中的方法,可以考虑改写下面这套流程
public function onMessage($clientId,$receive){
$receive = json_encode($receive, true);
if($receive && $receive['m']){
$method = $reveive['m'];//请求的方法
$args = $receive['args'];
try{
$operation = Operation::geteInstance();//实例化操作类
if(!method_exists($operation, $method)){
throw new \Exception(sprintf('the method "%s" does not exist for "%s"',get_class($operation)));
}
call_user_func_array(array($operation,$method),[$clientId,$args]);
}catch(\Exception $e){
echo $e->getMessage();
}
}
}
/*
public static function geteInstance(){
static $self;
if(!$self instanceof static){
$self = new static();
}
return $self;
}
*/
网友评论