File: //home/awaldron/_domains/api.alanwaldron.com/index.php
<?php
require_once 'stripe/init.php';
require_once 'v1/_globals.php';
define('E_FATAL', E_ERROR | E_USER_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_RECOVERABLE_ERROR);
define('ENV', 'production');
define('DISPLAY_ERRORS', TRUE);
define('ERROR_REPORTING', E_ALL & ~E_NOTICE);
define('LOG_ERRORS', FALSE);
register_shutdown_function('shut');
set_error_handler('handler');
ob_start();
// INIT VENDOR LIBRARIES
require_once 'vendor/phpmailer/phpmailer/src/Exception.php';
require_once 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require_once 'vendor/phpmailer/phpmailer/src/SMTP.php';
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// INCLUDE OUR ENDPOINT FILES
require_once 'v1/auth.php';
require_once 'v1/payments.php';
require_once 'v1/mail.php';
//require_once 'v1/misc.php';
require_once 'v1/members.php';
// SET CORS POLICY
cors();
// PARSE THE URL AND DATA
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', substr($_SERVER['REQUEST_URI'],1));
$function = strtolower($method.'_'.$request[0].'_'.$request[1].'_'.$request[2]);
// remove the first 3 items from the request
array_shift($request);
array_shift($request);
array_shift($request);
// format the post body
$body = [];
$postBody = file_get_contents('php://input');
if ( strlen($postBody) > 0 ) {
$body = json_decode( $postBody, true );
}
// Connect to the database
$db = dbconnect();
// Check the token
$auth_user = 1; //check_token( $db, $_SERVER['HTTP_AUTHORIZATION'] );
// Check if user is an Admin
$is_admin = true;
// Call the endpoint
if (function_exists($function)) {
call_user_func($function, $request, $body, $auth_user, $is_admin, $db);
} else {
response( 404, ['success'=>false,'error'=>'Endpoint not found...'.$function] );
}
ob_end_flush();