-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated methods and had a general clean-up of code comments etc.
- Loading branch information
Showing
6 changed files
with
95 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,19 @@ | |
|
||
namespace Ballen\Metar; | ||
|
||
/** | ||
* Metar | ||
* | ||
* Metar is a PHP 5.4+ library for retrieveing weather reports (METAR infomation), | ||
* the library supports multiple 'METAR prodivers' including NOAA and VATSIM. | ||
* | ||
* @author Bobby Allen <[email protected]> | ||
* @version 1.0.0 | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html | ||
* @link https://github.com/bobsta63/metar | ||
* @link http://www.bobbyallen.me | ||
* | ||
*/ | ||
class Metar | ||
{ | ||
|
||
|
@@ -11,10 +24,10 @@ class Metar | |
const SERVICES_NAMESPACE = 'Ballen\Metar\Providers'; | ||
|
||
/** | ||
* The METAR service of which to use to provide the METAR report. | ||
* @var string | ||
* Stores the requested airfield/port ICAO code. | ||
* @var string ICAO code. | ||
*/ | ||
private $metarProvider; | ||
private $icao; | ||
|
||
/** | ||
* The METAR string retrieved from the web service. | ||
|
@@ -23,32 +36,38 @@ class Metar | |
private $metar; | ||
|
||
/** | ||
* Gather METAR infomation for a given ICAO code. | ||
* @param string $icao Four-digital ICAO airport code. | ||
* @throws \InvalidArgumentException | ||
* The METAR service of which to use to provide the METAR report. | ||
* @var string METAR data provider class/file name. | ||
*/ | ||
private $metarProvider; | ||
|
||
/** | ||
* Initiates a new METAR object. | ||
* @param string $icao The airfeild/airport ICAO code. | ||
*/ | ||
public function __construct($icao) | ||
{ | ||
|
||
// We force the format of the ICAO code to be upper case! | ||
$icao = strtoupper($icao); | ||
$this->icao = strtoupper($icao); | ||
|
||
// Validate the ICAO code, just check some standard formatting stuff really! | ||
$this->validateIcao($icao); | ||
$this->validateIcao($this->icao); | ||
|
||
// Set a default provider, can be overrideen with 'setProvider()' function. | ||
$this->setProvider('NOAA'); | ||
|
||
$this->metar = (new $this->metarProvider($icao))->getMetarDataString(); | ||
} | ||
|
||
/** | ||
* Returns the string METAR message. | ||
* Returns the RAW METAR message as a string. | ||
* @return string The RAW METAR message. | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->metar; | ||
// We'll set the object 'metar' property to the station metar data as well as return the string so | ||
// that in future we can extend further and use the METAR string in other parts of our class after it has | ||
// been retrieved! | ||
return $this->metar = (string) new $this->metarProvider($this->icao); | ||
} | ||
|
||
/** | ||
|
@@ -64,8 +83,8 @@ private function validateIcao($icao) | |
} | ||
|
||
/** | ||
* | ||
* @param type $provider | ||
* Changes the default 'NOAA' METAR service provider to another one eg. 'VATSIM'. | ||
* @param string $provider METAR Provider Class/File name. | ||
*/ | ||
public function setProvider($provider = 'Noaa') | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,24 @@ | |
|
||
namespace Ballen\Metar\Providers; | ||
|
||
/** | ||
* Metar | ||
* | ||
* Metar is a PHP 5.4+ library for retrieveing weather reports (METAR infomation), | ||
* the library supports multiple 'METAR prodivers' including NOAA and VATSIM. | ||
* | ||
* @author Bobby Allen <[email protected]> | ||
* @version 1.0.0 | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html | ||
* @link https://github.com/bobsta63/metar | ||
* @link http://www.bobbyallen.me | ||
* | ||
*/ | ||
|
||
interface MetarProviderInterface | ||
{ | ||
|
||
function __construct($icao); | ||
|
||
function getMetarDataString(); | ||
function __toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,26 @@ | |
|
||
namespace Ballen\Metar\Providers; | ||
|
||
/** | ||
* Metar | ||
* | ||
* Metar is a PHP 5.4+ library for retrieveing weather reports (METAR infomation), | ||
* the library supports multiple 'METAR prodivers' including NOAA and VATSIM. | ||
* | ||
* @author Bobby Allen <[email protected]> | ||
* @version 1.0.0 | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html | ||
* @link https://github.com/bobsta63/metar | ||
* @link http://www.bobbyallen.me | ||
* | ||
*/ | ||
use \Ballen\Metar\Providers\MetarProviderInterface; | ||
use \Ballen\Metar\Helpers\MetarHTTPClient; | ||
|
||
/** | ||
* METAR service provided by the US NOAA (National Oceanic and Atmospheric Administration) | ||
* @link http://www.noaa.gov/ | ||
*/ | ||
|
||
class Noaa extends MetarHTTPClient implements MetarProviderInterface | ||
{ | ||
|
||
|
@@ -21,16 +33,21 @@ public function __construct($icao) | |
$this->icao = $icao; | ||
} | ||
|
||
public function getMetarDataString() | ||
private function getMetarDataString() | ||
{ | ||
|
||
$data = $this->getMetarAPIResponse(str_replace('{{_ICAO_}}', $this->icao, $this->serviceUrl)); | ||
|
||
// The NOAA web service provides a human readable timestamp of when the report was last generated but we don't care about that so we'll jump to the next line (the actual METAR string) | ||
$lines = explode($this->icao, $data); | ||
$data = trim($this->icao . $lines[1]); | ||
|
||
return $data; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getMetarDataString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,19 @@ | |
|
||
namespace Ballen\Metar\Providers; | ||
|
||
/** | ||
* Metar | ||
* | ||
* Metar is a PHP 5.4+ library for retrieveing weather reports (METAR infomation), | ||
* the library supports multiple 'METAR prodivers' including NOAA and VATSIM. | ||
* | ||
* @author Bobby Allen <[email protected]> | ||
* @version 1.0.0 | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html | ||
* @link https://github.com/bobsta63/metar | ||
* @link http://www.bobbyallen.me | ||
* | ||
*/ | ||
use \Ballen\Metar\Providers\MetarProviderInterface; | ||
use \Ballen\Metar\Helpers\MetarHTTPClient; | ||
|
||
|
@@ -20,7 +33,7 @@ public function __construct($icao) | |
$this->icao = $icao; | ||
} | ||
|
||
public function getMetarDataString() | ||
private function getMetarDataString() | ||
{ | ||
$data = $this->getMetarAPIResponse(str_replace('{{_ICAO_}}', $this->icao, $this->serviceUrl)); | ||
|
||
|
@@ -30,4 +43,9 @@ public function getMetarDataString() | |
return $data; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getMetarDataString(); | ||
} | ||
|
||
} |