|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
require_once("Flammenkuchen.php");
|
|
|
+require_once("CacheController.php");
|
|
|
|
|
|
class Router
|
|
|
{
|
|
|
@@ -53,39 +54,25 @@ class Router
|
|
|
$now = (int) (new \Datetime())->format("ymd");
|
|
|
if ($yymmdd != $this->LATEST)
|
|
|
{
|
|
|
- // TODO use index cache
|
|
|
if ((int) $yymmdd > $now) // Anti spoil
|
|
|
return null;
|
|
|
- if (file_exists("../data/${yymmdd}.json"))
|
|
|
- return $yymmdd;
|
|
|
- return null;
|
|
|
+ return (CacheFlammenkuchenManager::exists($yymmdd))
|
|
|
+ ? $yymmdd : null;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- $min = 0;
|
|
|
+ $cacheIndexData = CacheController::getCacheIndex()->getData();
|
|
|
+ $last = null;
|
|
|
|
|
|
- // obvious today-is-the-day
|
|
|
- if ($this->checkFileExists($now))
|
|
|
- return $now;
|
|
|
-
|
|
|
- //TODO use index cache
|
|
|
- $datadir = opendir("../data/");
|
|
|
- while (($file = readdir($datadir)) !== false)
|
|
|
+ foreach ($cacheIndexData as $currentYymmdd)
|
|
|
{
|
|
|
- if (is_dir("../data/".$file)
|
|
|
- || strlen($file) != 11
|
|
|
- || substr($file, 6) !== ".json")
|
|
|
- continue;
|
|
|
-
|
|
|
- $current = (int) substr($file, 0, 6);
|
|
|
-
|
|
|
- if ($current > $now)
|
|
|
- continue;
|
|
|
- if ($now - $current < $now - $min)
|
|
|
- $min = $current;
|
|
|
+ if ($currentYymmdd <= $now)
|
|
|
+ $last = $currentYymmdd;
|
|
|
+ else
|
|
|
+ break;
|
|
|
}
|
|
|
- closedir($datadir);
|
|
|
- return $min === 0 ? null : $min;
|
|
|
+
|
|
|
+ return $last;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -124,7 +111,12 @@ class Router
|
|
|
{
|
|
|
$req = $this->requestingDate;
|
|
|
|
|
|
- return Flammenkuchen::fromJson(json_decode(file_get_contents("../data/${req}.json")));
|
|
|
+ return CacheFlammenkuchenManager::get($req);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getRequestYymmdd()
|
|
|
+ {
|
|
|
+ return $this->requestingDate;
|
|
|
}
|
|
|
}
|
|
|
|