66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
||
namespace API;
|
||
//новая версия с классом api
|
||
|
||
$IP = $_SERVER['REMOTE_ADDR'];
|
||
|
||
foreach (glob("modules/*.php") as $filename) {
|
||
include $filename;
|
||
|
||
}
|
||
|
||
|
||
final class API
|
||
{
|
||
//подключение модулей
|
||
use Common, Companies, Devices, Stats, Users;
|
||
//стандартный шаблон singleton
|
||
private static $instance;
|
||
public static function getInstance(): API
|
||
{
|
||
if (null === static::$instance) {
|
||
static::$instance = new static();
|
||
}
|
||
|
||
return static::$instance;
|
||
}
|
||
private function __construct(){}
|
||
private function __clone(){}
|
||
private function __wakeup(){}
|
||
}
|
||
$api=API::getInstance();
|
||
|
||
$_POST = json_decode(file_get_contents('php://input'), true);
|
||
|
||
if (isset($_POST)) {
|
||
$params=$_POST['params'];
|
||
$flag=$params['flag'];
|
||
//echo ($flag);
|
||
if (method_exists($api, $flag)) {
|
||
call_user_func(array($api, $flag), $params);
|
||
} else {
|
||
header('Content-Type:text/html; charset=UTF-8', true, 301);
|
||
exit;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//старая версия без класса api
|
||
|
||
// foreach (glob("api/modules/*.php") as $filename) {
|
||
// include $filename;
|
||
// }
|
||
// $_POST = json_decode(file_get_contents('php://input'), true);
|
||
// if (isset($_POST)) {
|
||
// $params=$_POST['params'];
|
||
// $flag=$params['flag'];
|
||
// if (function_exists($flag)) {
|
||
// call_user_func($flag, $params);
|
||
// } else {
|
||
// header('Content-Type:text/html; charset=UTF-8', true, 301);
|
||
// exit;
|
||
// }
|
||
// }
|
||
|