定制 voku/weather 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

voku/weather

最新稳定版本:0.7.1

Composer 安装命令:

composer require voku/weather

包简介

Weather API Wrapper

README 文档

README

SWUbanner

Build Status codecov.io

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/

Install via "composer require"

composer require voku/weather
composer require voku/httpful # or another php-http/client-implementation e.g. "php-http/react-adapter" + "nyholm/psr7"

Usage:

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)

echo $weather->getTemperatureWithUnit(); // 17.1 °C

Example 2: (wind-speed with unit)

echo $weather->getWindSpeedWithUnit(); // 9 km/h

Unit Test:

  1. Composer is a prerequisite for running the tests.
composer install
  1. The tests can be executed by running this command from the root directory:
./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 (Microsoft) for hosting the code and a good infrastructure including Issues-Management, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to StyleCI for the simple but powerful code style check.
  • Thanks to PHPStan && Psalm for really great Static analysis tools and for discover bugs in the code!

统计信息

  • 总下载量: 176
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-14