stuarttodd-dev/weather-forecast-app
Composer 安装命令:
composer require stuarttodd-dev/weather-forecast-app
包简介
A package for retrieving weather forecasts based on IP addresses and timestamps.
README 文档
README
The PHP Weather Forecast Library is a PHP package that provides weather forecast information based on geolocation data. It uses external services to retrieve geolocation and weather forecast data.
Installation
Get an API Key from Open Weather API. Visit https://openweathermap.org/api/one-call-3 for more information.
You can install this library via Composer. Run the following command:
composer require stuarttodd-dev/weather-forecast-app
Configure composer.json
Package is still under development.
"minimum-stability": "dev",
Static Usage
use StuartToddDev\WeatherForecast\Services\WeatherForecast;
$weatherForecast = WeatherForecast::create('your-ip-address', 'your-open-weather-api-key');
$weatherForecast->getIpAddress(); // returns ip
$weatherForecast->getGeolocation(); // e.g {"status":"success","country":"United Kingdom","countryCode":"GB","region":"ENG","regionName":"England","city":"Stockton-on-Tees","zip":"TS18","lat":54.5579,"lon":-1.328,"timezone":"Europe/London","isp":"Virgin Media","org":"","as":"AS5089 Virgin Media Limited","query":"86.22.157.53"}
$weatherForecast->getForecast(); // Json string from open weather API (see https://openweathermap.org/api/one-call-3)
Inject API Services
use StuartToddDev\WeatherForecast\Services\WeatherForecast;
use StuartToddDev\WeatherForecast\Services\GeolocationIPAPI;
use StuartToddDev\WeatherForecast\Services\OpenWeatherAPI;
// Initialize the geolocation and weather forecast services
$geolocationAPI = new GeolocationIPAPI(new Client()); // first param is Guzzle client
$forecastAPI = new OpenWeatherAPI(new Client()'); // first param is Guzzle client
You can inject different API services (or adjust them) as long as they implement the relevant contracts (noted below).
// Initialize the WeatherForecast class
$weatherForecast = new WeatherForecast('your-ip-address', 'your-open-weather-api-key', $geolocationAPI, $forecastAPI);
$weatherForecast->getIpAddress(); // returns ip
$weatherForecast->getGeolocation(); // e.g {"status":"success","country":"United Kingdom","countryCode":"GB","region":"ENG","regionName":"England","city":"Stockton-on-Tees","zip":"TS18","lat":54.5579,"lon":-1.328,"timezone":"Europe/London","isp":"Virgin Media","org":"","as":"AS5089 Virgin Media Limited","query":"86.22.157.53"}
$weatherForecast->getForecast(); // Json string from open weather API (see https://openweathermap.org/api/one-call-3)
ForecastContract
Used by OpenWeatherAPI
public function setLon(string $lon): self;
public function getLon(): string;
public function setLat(string $lat): self;
public function getLat(): string;
public function setApiKey(string $apiKey): self;
public function getForecast(): ?string;
GeolocationContract
Used by GeolocationIPAPI
interface GeolocationContract
{
public function setIPAddress(string $ipAddress): self;
public function getIPAddress(): ?string;
public function getGeoLocation(): ?string;
}
stuarttodd-dev/weather-forecast-app 适用场景与选型建议
stuarttodd-dev/weather-forecast-app 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 stuarttodd-dev/weather-forecast-app 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stuarttodd-dev/weather-forecast-app 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-20