<?php
class HaconDemoHAFASAPI
{
    private $accessId;

    private $trace;

    function __construct($accessId, $trace = FALSE)
    {
        $this->accessId = $accessId;

        $this->trace = $trace;
    }

    private function call($tapiUrl)
    {
        try {
            $response = file_get_contents($tapiUrl);
            if ($response !== false) {
                $response = json_decode($response, true);
            }
        } catch (Exception $ex) {
            if ($this->trace) {
                $traceOutput["Message"] = $ex->getMessage();

                $traceOutput["url"] = str_replace($this->appId, "", str_replace($this->accessId, "", $tapiUrl));

                echo "<xmp>";
                print_r($traceOutput);
                echo "</xmp>";
            }
        }

        return (isset($response) ? $response : false);
    }

    public function Journeys(string $from, string $to, string $date, string $time)
    {
        return $this->call("https://trainline-uk.demo.hafas.de/restproxy/trip?accessId={$this->accessId}&originId=A=1@O={$from}@&destId=A=1@O={$to}@&date={$date}&time={$time}&showPassingPoints=1&passlist=1");
    }
}
