game2006api/webapp/index.php
aozhiwei 3d966c69ed 1
2024-07-25 11:30:20 +08:00

71 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require '../config/config.php';
require '../config/routes.php';
require 'bootstrap/init.php';
if (empty($_REQUEST['c']) || empty($_REQUEST['a'])) {
die();
return;
}
function autoload_controller__($classname)
{
$fileName = "controller/$classname.class.php";
if (!file_exists($fileName)) {
if (SERVER_ENV == _ONLINE) {
die();
}
}
require_once $fileName;
spl_autoload_unregister('autoload_controller__');
}
spl_autoload_register('autoload_controller__');
function isValidActionAction($a, $method) {
return $method && $method->isPublic() &&
$a[0] != '_' &&
(!$method->isConstructor() && !$method->isDestructor());
}
try{
$c = $_REQUEST['c'];
$a = $_REQUEST['a'];
if (!empty($gOnlyRoutes) && !getXVal($gOnlyRoutes, $c, null)) {
die();
return;
}
if (!empty($gExcludeRoutes) && getXVal($gExcludeRoutes, $c, null)) {
die();
return;
}
$classname = $c .'Controller';
$beginTick = phpcommon\getTickCount();
$obj = eval('return new $classname();');
$method = null;
try {
$method = new ReflectionMethod($classname, $a);
} catch (Exception $e) {
}
$methodS = null;
try {
$methodS = new ReflectionMethod($classname, $a . 'S');
} catch (Exception $e){
}
if (isValidActionAction($a, $method)) {
$obj->_handlePre();
$method->invoke($obj);
$obj->_handlePost();
} else if (isValidActionAction($a, $methodS)) {
//如果原版函数不存在并且S版函数存在则自动切换为S版
echo json_encode(array(
'errcode' => 1006,
'errmsg' => 'already upgrade to safe api',
'payload' => 1,
));
die();
}
} catch (Exception $e){
error_log($e);
}