voku / weather
天气API包装器
0.7.1
2023-07-24 00:06 UTC
Requires
- php: 8.1.*||8.2.*
- psr/http-client-implementation: *
- psr/http-factory-implementation: *
Requires (Dev)
- php-cs-fixer/shim: v3.22.*
- phpstan/phpstan: 1.10.*
- phpunit/phpunit: 9.6.*
- voku/httpful: 3.0.*
- dev-main
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- dev-renovate/php-cs-fixer-shim-3.x
- dev-renovate/php-8.x
- dev-renovate/phpstan-packages
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/shivammathur-setup-php-2.x
- dev-renovate/actions-cache-4.x
- dev-renovate/major-github-artifact-actions
- dev-renovate/codecov-codecov-action-4.x
- dev-renovate/actions-cache-3.x
- dev-whitesource/configure
This package is auto-updated.
Last update: 2024-08-31 01:57:40 UTC
README
天气数据包装器
这是一个围绕“Bright Sky”(https://brightsky.dev/)天气API的简单包装器。
- 您可以通过实现另一个天气提供者类简单地替换天气API。
演示:(https://github.com/voku/weather-demo)
http://weather-demo.suckup.de/
通过"composer require"安装
composer require voku/weather
composer require voku/httpful # or another php-http/client-implementation e.g. "php-http/react-adapter" + "nyholm/psr7"
用法
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
示例 1: (带有单位的温度)
echo $weather->getTemperatureWithUnit(); // 17.1 °C
示例 2: (带有单位的风速)
echo $weather->getWindSpeedWithUnit(); // 9 km/h
单元测试
- Composer是运行测试的前提条件。
composer install
- 可以从根目录运行此命令来执行测试
./vendor/bin/phpunit
AbstractHttpProvider 方法
getSources(): WeatherSourceDto[]
参数: 无
返回
\WeatherSourceDto[]
getWeatherCurrent(voku\weather\WeatherQueryDto $query)
参数
voku\weather\WeatherQueryDto $query
返回
voku\weather\WeatherDto
getWeatherForecast(voku\weather\WeatherQueryDto $query)
参数
voku\weather\WeatherQueryDto $query
返回
voku\weather\WeatherDto
getWeatherForecastCollection(voku\weather\WeatherQueryDto $query)
参数
voku\weather\WeatherQueryDto $query
返回
voku\weather\WeatherCollection
getWeatherHistorical(voku\weather\WeatherQueryDto $query)
参数
voku\weather\WeatherQueryDto $query
返回
voku\weather\WeatherDto
getWeatherHistoricalCollection(voku\weather\WeatherQueryDto $query)
参数
voku\weather\WeatherQueryDto $query
返回
voku\weather\WeatherCollection