<?php
error_reporting(1);

define('BASE', realpath(dirname(__FILE__).'/../../') . '/');

require BASE.'public/api/controller/MarktAPIController.php';

// Requests from the same server don't have a HTTP_ORIGIN header
if (!array_key_exists('HTTP_ORIGIN', $_SERVER))
{
    $_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME'];
}

switch ($_SERVER['HTTP_X_API_VERSION'])
{
    case '1.0':
    default:
    try {
        $API = new MarktAPIController($_REQUEST['endpoint'], $_SERVER['HTTP_ORIGIN']);
        echo $API->processAPI();
    } catch (Exception $e) {
        echo json_encode(Array('error' => $e->getMessage()));
    }
    break;
}
?>
