https://github.com/voku/weather
https://github.com/voku/weather
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/voku/weather
- Owner: voku
- License: mit
- Created: 2023-07-14T03:23:38.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-15T12:57:02.000Z (6 months ago)
- Last Synced: 2025-04-21T03:25:33.406Z (6 months ago)
- Language: PHP
- Size: 63.5 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
[//]: # (AUTO-GENERATED BY "PHP README Helper": base file -> docs/base.md)
[](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)[](https://github.com/voku/weather/actions)
[](http://codecov.io/github/voku/weather?branch=main)# Weather Data Wrapper
This is a simple wrapper around the "Bright Sky" (https://brightsky.dev/) weather api.
+ you can simply replace the weather api by implementing another weather provider class.### DEMO: (https://github.com/voku/weather-demo)
[http://weather-demo.suckup.de/](http://weather-demo.suckup.de/)### Install via "composer require"
```shell
composer require voku/weather
composer require voku/httpful # or another php-http/client-implementation e.g. "php-http/react-adapter" + "nyholm/psr7"
```### Usage:
```php
use voku\weather\provider\BrightskyHttpProvider;
use voku\weather\WeatherQueryDto;require_once __DIR__ . '/vendor/autoload.php'; // example path
$latitude = 48.137154;
$longitude = 11.576124;
$dateTime = new \DateTimeImmutable('2023-01-01 12:00:00');$weatherQuery = new WeatherQueryDto(
$latitude,
$longitude,
$dateTime
);$weather = (new BrightskyHttpProvider())->getWeatherHistorical($weatherQuery);
echo $weather->temperature; // 17.1
```Example 1: (temperature with unit)
```php
echo $weather->getTemperatureWithUnit(); // 17.1 °C
```Example 2: (wind-speed with unit)
```php
echo $weather->getWindSpeedWithUnit(); // 9 km/h
```### Unit Test:
1) [Composer](https://getcomposer.org) is a prerequisite for running the tests.
```
composer install
```2) The tests can be executed by running this command from the root directory:
```bash
./vendor/bin/phpunit
```## AbstractHttpProvider methods
getSources
getWeatherCurrent
getWeatherForecast
getWeatherForecastCollection
getWeatherHistorical
getWeatherHistoricalCollection## getSources(): WeatherSourceDto[]
↑**Parameters:**
__nothing__**Return:**
- `\WeatherSourceDto[]`--------
## getWeatherCurrent(voku\weather\WeatherQueryDto $query):
↑**Parameters:**
- `voku\weather\WeatherQueryDto $query`**Return:**
- `voku\weather\WeatherDto`--------
## getWeatherForecast(voku\weather\WeatherQueryDto $query):
↑**Parameters:**
- `voku\weather\WeatherQueryDto $query`**Return:**
- `voku\weather\WeatherDto`--------
## getWeatherForecastCollection(voku\weather\WeatherQueryDto $query):
↑**Parameters:**
- `voku\weather\WeatherQueryDto $query`**Return:**
- `voku\weather\WeatherCollection`--------
## getWeatherHistorical(voku\weather\WeatherQueryDto $query):
↑**Parameters:**
- `voku\weather\WeatherQueryDto $query`**Return:**
- `voku\weather\WeatherDto`--------
## getWeatherHistoricalCollection(voku\weather\WeatherQueryDto $query):
↑**Parameters:**
- `voku\weather\WeatherQueryDto $query`**Return:**
- `voku\weather\WeatherCollection`--------
### Thanks
- Thanks to [GitHub](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Management, etc.
- Thanks to [IntelliJ](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to [StyleCI](https://styleci.io/) for the simple but powerful code style check.
- Thanks to [PHPStan](https://github.com/phpstan/phpstan) && [Psalm](https://github.com/vimeo/psalm) for really great Static analysis tools and for discover bugs in the code!