2019-08-09 02:52:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Contracts\Metar as MetarProvider;
|
|
|
|
use App\Contracts\Service;
|
|
|
|
use App\Support\Metar;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AnalyticsService
|
|
|
|
*/
|
|
|
|
class AirportService extends Service
|
|
|
|
{
|
|
|
|
private $metarProvider;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
MetarProvider $metarProvider
|
|
|
|
) {
|
|
|
|
$this->metarProvider = $metarProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the METAR for a given airport
|
|
|
|
*
|
|
|
|
* @param $icao
|
|
|
|
*
|
|
|
|
* @return Metar|null
|
|
|
|
*/
|
2019-08-09 05:41:53 +08:00
|
|
|
public function getMetar($icao)
|
2019-08-09 02:52:34 +08:00
|
|
|
{
|
2019-08-09 05:41:53 +08:00
|
|
|
$icao = trim($icao);
|
|
|
|
if ($icao === '') {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-09 02:52:34 +08:00
|
|
|
|
2019-08-09 05:41:53 +08:00
|
|
|
$raw_metar = $this->metarProvider->get_metar($icao);
|
2019-08-09 02:52:34 +08:00
|
|
|
if ($raw_metar && $raw_metar !== '') {
|
|
|
|
return new Metar($raw_metar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|