<?php

// Production: never expose PHP warnings, stack paths or configuration details.
ini_set('display_errors', '0');
ini_set('display_startup_errors', '0');
error_reporting(E_ALL);
ini_set('log_errors', '1');

spl_autoload_register(function ($class) {

    $prefix = 'Zoo\\';

    if (substr($class, 0, strlen($prefix)) !== $prefix) {
        return;
    }

    $relative = substr($class, strlen($prefix));

    $path = '/home/fcaglobal/zoo_roulette_start/server/src/'
          . str_replace('\\', '/', $relative)
          . '.php';

    if (file_exists($path)) {
        require_once $path;
    }
});

header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('Referrer-Policy: no-referrer');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');

function input_json()
{
    $raw = file_get_contents('php://input');

    if (!$raw) {
        $raw = '{}';
    }

    $data = json_decode($raw, true);

    return is_array($data) ? $data : array();
}

function json_out($data, $status = 200)
{
    http_response_code($status);

    echo json_encode(
        $data,
        JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE
    );

    exit;
}