71 lines
1.8 KiB
PHP
71 lines
1.8 KiB
PHP
<?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);
|
||
}
|