Files
_api_server_vue/core__.php
2026-01-13 12:36:57 +03:00

66 lines
1.5 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
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;
// }
// }