phpvms/app/Widgets/Weather.php

47 lines
1.0 KiB
PHP
Raw Normal View History

<?php
namespace App\Widgets;
use App\Contracts\Widget;
2018-04-07 22:05:06 +08:00
use App\Support\Metar;
/**
* This is a widget for the 3rd party CheckWX service
*/
class Weather extends Widget
{
protected $config = [
'icao' => null,
];
public const URL = 'https://avwx.rest/api/metar/';
/**
* Attempt to get the data from the CheckWX API
*/
public function run()
{
/**
* @var \App\Contracts\Metar
*/
$klass = config('phpvms.metar');
2018-08-27 00:40:04 +08:00
$metar_class = new $klass();
2018-04-04 22:04:14 +08:00
$metar = null;
$wind = null;
$raw_metar = $metar_class->get_metar($this->config['icao']);
if ($raw_metar && $raw_metar !== '') {
$metar = new Metar($raw_metar);
2018-04-04 22:04:14 +08:00
}
return view('widgets.weather', [
'config' => $this->config,
'metar' => $metar,
'unit_alt' => setting('units.altitude'),
'unit_dist' => setting('units.distance'),
'unit_temp' => setting('units.temperature'),
]);
}
}