2018-04-03 11:35:25 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Metar;
|
|
|
|
|
|
|
|
use App\Interfaces\Metar;
|
|
|
|
use App\Support\Http;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the raw METAR string from the NOAA Aviation Weather Service
|
|
|
|
* @package App\Services\Metar
|
|
|
|
*/
|
|
|
|
class AviationWeather extends Metar
|
|
|
|
{
|
2018-04-03 11:44:31 +08:00
|
|
|
private const METAR_URL =
|
2018-04-03 11:35:25 +08:00
|
|
|
'https://www.aviationweather.gov/adds/dataserver_current/httpparam?'
|
|
|
|
.'dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3'
|
|
|
|
.'&mostRecent=true&fields=raw_text&stationString=';
|
|
|
|
|
|
|
|
/**
|
2018-04-03 11:44:31 +08:00
|
|
|
* Implement the METAR - Return the string
|
2018-04-03 11:35:25 +08:00
|
|
|
* @param $icao
|
2018-04-03 11:44:31 +08:00
|
|
|
* @return string
|
2018-04-03 11:35:25 +08:00
|
|
|
*/
|
2018-04-03 11:44:31 +08:00
|
|
|
protected function metar($icao): string
|
2018-04-03 11:35:25 +08:00
|
|
|
{
|
2018-04-03 11:44:31 +08:00
|
|
|
$url = static::METAR_URL.$icao;
|
2018-04-03 11:35:25 +08:00
|
|
|
$res = Http::get($url, []);
|
|
|
|
$xml = simplexml_load_string($res);
|
|
|
|
return $xml->data->METAR->raw_text;
|
|
|
|
}
|
|
|
|
}
|