| Server IP : 95.46.96.79 / Your IP : 216.73.216.4 Web Server : Apache/2.4.41 (Ubuntu) System : Linux zaimer.uz 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : akslabs_uz_usr ( 1001) PHP Version : 7.4.3-4ubuntu2.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/sugurtatrip__usr95/data/www/sugurtatrip.uz/apiv1/policy/ |
Upload File : |
<?php
use Api\ReferralController;
use Api\BaseController;
require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Autoload classes
spl_autoload_register(function ($class) {
$path = 'src/' . str_replace('\\', '/', $class) . '.php';
if (file_exists($path)) {
include $path;
}
});
// Initialize logger and database
$logger = new Core\Logger();
$db = new Core\DB();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$rawData = file_get_contents('php://input');
$data = json_decode($rawData, true);
if ($data) {
$logger->log('Received request data: ' . $rawData);
$api_list = getApiList();
$results = [];
$request_id = null;
if (isset($data['partner_id'])) {
$referralController = new ReferralController();
$request_id = $referralController->handle_partner_id($data);
}
if (isset($data['request_id']) && $data['request_id'] !== '' && ctype_digit((string)$data['request_id'])) {
$request_id = (int)$data['request_id'];
}
foreach ($api_list as $api_name) {
$class_name = 'Api\\' . ucfirst($api_name) . 'Controller';
if (class_exists($class_name)) {
$api = new $class_name($request_id);
$price = $api->handle_request($data);
$preparedData = $api->prepareData($price);
$logger->log($class_name . ' response data: ' . json_encode($preparedData));
$results[] = $preparedData;
} else {
$logger->log('Class ' . $class_name . ' not found');
}
}
header('Content-Type: application/json');
echo json_encode([ 'request_id' => $request_id, 'data' => $results], JSON_UNESCAPED_UNICODE);
} else {
$logger->log('No data provided in JSON request', "error");
echo json_encode(['error' => 'No data provided in JSON request']);
}
} else {
$logger->log('Invalid request method', "error");
echo json_encode(['error' => 'Invalid request method']);
}
function getApiList()
{
global $db;
global $logger;
$result = $db->query("SELECT name FROM partners WHERE active = 1");
$api_list = [];
if ($result && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$api_list[] = $row['name'];
}
} else {
$logger->log('No APIs found in the database');
}
return $api_list;
}