在events.php
中的onMessage方法, 作为路由分发, 报错类找不到.
已经引入spl_autoload_register
;
求大佬们指点
//spl_autoload_register文件
/**
* @param $class
*/
function loadPrint($class)
{
$file = 'Controller\\' . $class . '.php';
$file = str_replace("\\", "/", $file);
if (is_file($file)) {
var_dump($file);
require_once($file);
}
return;
}
spl_autoload_register('loadPrint');
composer文件
"autoload": {
"psr-4": {
"" : "./",
"" : "Applications/five/"
}
}
目录:
Events.php
<?php
//declare(ticks=1);
include_once 'spl_autoload_register.php';
use \GatewayWorker\Lib\Gateway;
public static function onMessage($client_id, $message)
{
echo "onMessage:".$message."\n";
$data = json_decode($message, true);
switch ($data['type']){
case "pong":
return;
case "login":
User::login($client_id, $message);
return ;
default:
//{"type":"reaq","class":"User","method":"test","para":{"nick":"tex","sex":"1"}}
$class = new $data['class'];
$method = $data['method'];
$para = $data['para'];
call_user_func_array($class."::".$method, $para);
return;
}
}
报错
Error: Class "User" not found in Events.php:57