feat: /api/data.php with fixture source, robots.txt
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Weerscherm\Cache;
|
||||
use Weerscherm\Config;
|
||||
use Weerscherm\DashboardService;
|
||||
use Weerscherm\FixtureSource;
|
||||
use Weerscherm\LiveSource;
|
||||
|
||||
$root = dirname(__DIR__, 2);
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('Cache-Control: no-store');
|
||||
header('X-Robots-Tag: noindex');
|
||||
|
||||
require $root . '/vendor/autoload.php';
|
||||
|
||||
$configFile = $root . '/config.php';
|
||||
if (!is_file($configFile)) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['errors' => ['config_missing'], 'message' => 'config.php ontbreekt: kopieer config.example.php naar config.php']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$config = Config::load($configFile);
|
||||
$storage = rtrim((string) $config->get('storage_path'), '/');
|
||||
$timezone = (string) $config->get('timezone');
|
||||
$lat = $config->get('forecast_lat');
|
||||
$lon = $config->get('forecast_lon');
|
||||
|
||||
$source = $config->get('data_source') === 'live'
|
||||
? LiveSource::fromConfig($config)
|
||||
: new FixtureSource(null, $timezone);
|
||||
|
||||
$service = new DashboardService(
|
||||
$source,
|
||||
new Cache($storage . '/cache'),
|
||||
$config->get('cache_ttl'),
|
||||
$timezone,
|
||||
is_numeric($lat) ? (float) $lat : null,
|
||||
is_numeric($lon) ? (float) $lon : null,
|
||||
is_array($config->get('indoor_modules')) ? $config->get('indoor_modules') : [],
|
||||
is_string($config->get('netatmo_device_id')) && $config->get('netatmo_device_id') !== '' ? $config->get('netatmo_device_id') : null,
|
||||
);
|
||||
|
||||
echo json_encode($service->build(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
} catch (Throwable $e) {
|
||||
error_log('weerscherm: ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
echo json_encode(['errors' => ['server_error']]);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
User-agent: *
|
||||
Disallow: /
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Weerscherm;
|
||||
|
||||
/** Echte bronnen: Netatmo (stationsdata, regenmetingen) en Open-Meteo (verwachting). Wordt in fase 3/4 ingevuld. */
|
||||
final class LiveSource implements WeatherSource
|
||||
{
|
||||
public static function fromConfig(Config $config): self
|
||||
{
|
||||
throw new \RuntimeException('LiveSource is nog niet beschikbaar; gebruik data_source = fixture');
|
||||
}
|
||||
|
||||
public function stationsData(): array
|
||||
{
|
||||
throw new UpstreamException('niet geïmplementeerd');
|
||||
}
|
||||
|
||||
public function measure(string $deviceId, string $moduleId, int $begin, int $end): array
|
||||
{
|
||||
throw new UpstreamException('niet geïmplementeerd');
|
||||
}
|
||||
|
||||
public function forecast(float $lat, float $lon, string $timezone): array
|
||||
{
|
||||
throw new UpstreamException('niet geïmplementeerd');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user