Files
api/services/nginx/app/index.php
T
Jepp9350 e09eedb010 Add statistics feature with bookings tracking functionality
Introduce a scalable statistics architecture including `statistics` class, interface, and related implementations. Added support for tracking new bookings with routes and data handling through `bookings_s` and `statistic_t`. Integrated the feature into the application using autoloaders and response mechanisms.
2025-01-31 12:32:22 +01:00

127 lines
3.4 KiB
PHP

<?php global /** @var response $response */
$DEBUG, $CONFIG_DB, $ENCRYPTION_KEY, $CORS, $WD, $db, $response, $request, $router, $redis;
/**
* This is the main entry point to the Truck Wash API.
*/
const WD = __DIR__;
require_once 'config.php';
/** Debug */
if ($DEBUG) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
/** CORS */
header("Access-Control-Allow-Origin: $CORS");
header("Access-Control-Allow-Headers: Content-Type, Authorization");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
/** Autoload */
require_once 'vendor/autoload.php';
/** Load all Interfaces */
foreach ( glob(WD . '/interfaces/*.php') as $interface ) {
require_once $interface;
}
/** Load all Traits */
foreach ( glob(WD . '/traits/*.php') as $trait ) {
require_once $trait;
}
/**
* Load all statistics
*/
foreach ( glob(WD . '/statistics/*.php') as $statistic ) {
require_once $statistic;
}
/** Load all Classes */
require_once 'classes/encrypt.php';
require_once 'classes/authentication.php';
require_once 'classes/object_property.php';
require_once 'classes/router.php';
require_once 'classes/db.php';
require_once 'classes/response.php';
require_once 'classes/request.php';
require_once 'classes/ratelimit.php';
require_once 'classes/wash_certificate_store.php';
require_once 'classes/redis.php';
require_once 'classes/slack.php';
require_once 'classes/wordpress_bookings_remote.php';
require_once 'classes/language_packs.php';
require_once 'classes/economic.php';
require_once 'classes/statistics.php';
/**
* Modules
* Load all the modules
*/
require_once 'modules/economic/economic_m.php';
require_once 'modules/economic/customers/economicCustomers.php';
require_once 'modules/economic/customers/economic_customer_mo.php';
require_once 'modules/economic/invoices/draft/economicInvoicesDrafts.php';
require_once 'modules/economic/invoices/draft/economic_invoice_draft_mo.php';
use classes\db;
use classes\redis;
use classes\request;
use classes\response;
use classes\router;
// Start the session
$router = new router();
$response = new response();
$request = new request();
$db = new db($CONFIG_DB);
try {
define("redis", (new redis())->connect());
} catch (Exception $e) {
$response->error($e->getMessage(), 500);
}
// Connect to the database, and ensure the connection is successful
try {
$db->connect();
} catch (Exception $e) {
$response->error($e->getMessage(), 500);
}
// Load all the traits
foreach ( glob(WD . '/traits/*.php') as $trait ) {
require_once $trait;
}
// Load all the routes
foreach ( glob(WD . '/routes/*.php') as $route ) {
require_once $route;
}
/** Load all Objects */
foreach ( glob(WD . '/objects/*.php') as $object ) {
try {
require_once $object;
} catch (Exception $e) {
$response->error($e->getMessage(), 500);
}
}
// If the program was called from the command line, run the cli script
if (php_sapi_name() === 'cli' || isset($_GET['internalCronCall'])) {
require_once 'cli.php';
exit;
}
// If the route ends with .php, then require the file_server.php
if (str_contains($_SERVER['REQUEST_URI'], '.pdf')) {
require_once 'file_server.php';
exit;
}
// Autoload all the routes
$router->auto_load_routes(WD . '/routes');
/** If no matching route is found, return a 404 */
if (!$response->is_matching_route_found()) {
// Debug
$response->add_debug(['message' => 'No matching route found']);
$response->not_found();
}