<?php
ob_start("ob_gzhandler");
require_once('config.php');
require 'vendor/autoload.php';
require_once(PATH_CORE.'Mail.php');
require_once(PATH_CORE.'ErrorHandler.php');
require_once(PATH_CORE.'Database.php');
require_once(PATH_CORE.'User.php');
require_once(PATH_CORE.'Routes.php');

\Cloudinary::config(array(
  "cloud_name" => CLOUDINARY_NAME,
  "api_key" => CLOUDINARY_API_KEY,
  "api_secret" => CLOUDINARY_API_SECRET
));

$errorHandler = new ErrorHandler();
$database = new Database(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

$module = isset($_REQUEST['module']) ?  $_REQUEST['module'] : 'dashboards';
$controller = isset($_REQUEST['controller']) ?  $_REQUEST['controller'] : 'page';
$action = isset($_REQUEST['action']) ?  $_REQUEST['action'] : '';
$apiVersion = isset($_REQUEST['version']) ?  $_REQUEST['version'] : 'v1';

$authToken = isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : null;

$user = new User($authToken);
$route = new Route($user, $apiVersion);
require(ROOT_DIR . PATH_COMPONENTS . $apiVersion . '/home/' . $controller . 'Template.php');

$database->closeConnection();
