Initial commit
This commit is contained in:
56
rss/php/handler.php
Normal file
56
rss/php/handler.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
define('BASE', realpath(dirname(__FILE__) . '/../../'));
|
||||
require_once(BASE . '/rss/php/autoload.php');
|
||||
use Vor\core\Sys;
|
||||
Sys::start();
|
||||
|
||||
$classMap = [
|
||||
// Add public allowed classes
|
||||
'Frontend' => \Vor\application\Frontend::class,
|
||||
];
|
||||
|
||||
$methodMap = [
|
||||
// Add public allowed methods
|
||||
'Frontend' => ['clean'],
|
||||
];
|
||||
|
||||
$target = trim((string)($_POST['target'] ?? ''));
|
||||
$method = trim((string)($_POST['method'] ?? ''));
|
||||
|
||||
if($target === '' || $method === ''){
|
||||
Sys::json(['status' => 'fail', 'message' => 'Missing target'], 400);
|
||||
}
|
||||
|
||||
if(!isset($classMap[$target])){
|
||||
Sys::json(['status' => 'fail', 'message' => 'Invalid class'], 404);
|
||||
}
|
||||
|
||||
if(!in_array($method, $methodMap[$target] ?? [], true)){
|
||||
Sys::json(['status' => 'fail', 'message' => 'Invalid method'], 404);
|
||||
}
|
||||
|
||||
$obj = new $classMap[$target];
|
||||
|
||||
foreach($_POST as $k => $v){
|
||||
if($k === 'target' || $k === 'method'){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(property_exists($obj, $k)){
|
||||
$obj->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(($_FILES ?? []) as $k => $v){
|
||||
if(property_exists($obj, $k)){
|
||||
$obj->$k = $v;
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
$resp = $obj->$method();
|
||||
Sys::json(['status' => $resp ? 'success' : 'fail', 'message' => $resp], 200);
|
||||
}catch(\Throwable $e){
|
||||
error_log($e->getMessage());
|
||||
Sys::json(['status' => 'fail', 'message' => 'Server error'], 500);
|
||||
}
|
||||
Reference in New Issue
Block a user