openstamanager/api/index.php

69 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2020-07-28 16:37:44 +02:00
use API\Response;
function serverError()
{
$error = error_get_last();
if ($error['type'] == E_ERROR) {
ob_end_clean();
2019-07-19 15:23:00 +02:00
echo Response::error('serverError');
}
}
// Gestione degli errori
set_error_handler('serverError');
register_shutdown_function('serverError');
include_once __DIR__.'/../core.php';
// Permesso di accesso all'API da ogni dispositivo
header('Access-Control-Allow-Origin: *');
2018-08-01 15:15:14 +02:00
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
try {
2019-07-19 15:23:00 +02:00
$response = Response::manage();
} catch (Exception $e) {
2018-07-27 12:17:17 +02:00
// Log dell'errore
$logger = logger();
2024-01-15 15:30:45 +01:00
$logger->addRecord(Monolog\Logger::ERROR, $e);
2018-07-27 12:17:17 +02:00
2019-07-19 15:23:00 +02:00
$response = Response::error('serverError');
}
2018-08-01 15:15:14 +02:00
// Richiesta OPTIONS (controllo da parte del dispositivo)
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
2019-07-19 15:23:00 +02:00
$response = Response::error('ok');
2018-08-01 15:15:14 +02:00
}
json_decode($response);
2018-06-29 15:57:12 +02:00
// Impostazioni di Content-Type e Charset Header
if (json_last_error() == JSON_ERROR_NONE) {
header('Content-Type: application/json; charset=UTF-8');
} else {
header('Content-Type: text/plain; charset=UTF-8');
}
// Stampa dei risultati
echo $response;
2022-11-23 16:45:46 +01:00
2023-08-04 14:54:28 +02:00
Auth::logout();