previousnext / bom-weather
PHP lib for accessing the Australian Bureau of Meteorology (BOM) weather forecasts and observations.
1.0.0-alpha2
2026-04-21 01:24 UTC
Requires
- php: ^8.1
- ext-xml: *
- psr/http-client: ^1.0
- psr/http-client-implementation: *
- psr/http-factory: ^1.0
- psr/http-factory-implementation: *
- psr/http-message: ^1.0 || ^2.0
- psr/http-message-implementation: *
- psr/log: ^3.0
- symfony/serializer: ^6.4 || ^7.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.2
- guzzlehttp/psr7: ^2.9
- http-interop/http-factory-guzzle: ^1.2.1
- php-http/mock-client: ^1.6.1
- phpstan/phpstan: ^2.1.50
- phpunit/phpunit: ^11.5.55
- previousnext/coding-standard: ^1.1.1
- staabm/annotate-pull-request-from-checkstyle: ^1.8.6
This package is auto-updated.
Last update: 2026-04-21 04:55:34 UTC
README
A PHP library for fetching data from the Australian Bureau of Meteorology API.
Installation
composer require previousnext/bom-weather php-http/discovery
The library requires a PSR-18 HTTP client and PSR-17 HTTP factories. We recommend using Guzzle.
Usage
Forecasts
$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $client = new BomClient($httpClient, $requestFactory, new NullLogger()); $forecast = $client->getForecast('IDN10031'); $issueTime = $forecast->getIssueTime(); $regions = $forecast->getRegions(); $metros = $forecast->getMetropolitanAreas(); $locations = $forecast->getLocations(); foreach ($locations as $location) { $aac = $location->getAac(); $desc = $location->getDescription(); /** @var \BomWeather\Forecast\ForecastPeriod[] $periods */ $periods = $location->getForecastPeriods(); // Usually 7 days of forecast data. foreach ($periods as $period) { $date = $period->getStartTime(); $maxTemp = $period->getAirTempMaximum(); $precis = $period->getPrecis(); } }
Warnings
$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $client = new BomClient($httpClient, $requestFactory, new NullLogger()); $warning = $client->getWarning('IDN20400'); $issueTime = $warning->getIssueTime(); // Warning info contains the title and advice. $warningInfo = $warning->getWarningInfo(); $title = $warningInfo->getWarningTitle(); $nextIssue = $warningInfo->getWarningNextIssue(); // Areas affected by the warning. $regions = $warning->getRegions(); $coasts = $warning->getCoasts(); foreach ($regions as $region) { $aac = $region->getAac(); $description = $region->getDescription(); }
Observations
$httpClient = new GuzzleHttp\Client(['base_uri' => 'http://www.bom.gov.au/']); $requestFactory = new Http\Factory\Guzzle\RequestFactory(); $client = new BomClient($httpClient, $requestFactory, new NullLogger()); $observationList = $client->getObservationList('IDN60901', '95757'); $refreshMessage = $observationList->getRefreshMessage(); // Get the latest observation. $observation = $observationList->getLatest(); $rain = $observation->getRainSince9am(); // Station information. $station = $observation->getStation(); $name = $station->getName(); // Temperature observations. $temperature = $observation->getTemperature(); $airTemp = $temperature->getAirTemp(); $apparentTemp = $temperature->getApparentTemp(); $relativeHumidity = $temperature->getRealtiveHumidity(); // Wind observations. $wind = $observation->getWind(); $direction = $wind->getDirection(); $speedKmh = $wind->getSpeedKmh(); $gustKmh = $wind->getGustKmh(); // Pressure observations. $pressure = $observation->getPressure(); $qnh = $pressure->getQnh(); $meanSeaLevel = $pressure->getMeanSeaLevel();
Developing
PHP CodeSniffer
./bin/phpcs
PHPUnit
./bin/phpunit
PHPStan
./bin/phpstan