mrcnpdlk/weather-api
Composer 安装命令:
composer require mrcnpdlk/weather-api
包简介
Weather API and air quality for Poland
README 文档
README
Contents
Installation
Install the latest version with composer
composer require mrcnpdlk/weather-api
Basic usage
Cache
Library supports Cache bundles based on PSR-16 standard.
For below example was used phpfastcache/phpfastcache V7.
phpfastcache/phpfastcache supports a lot of endpoints, i.e. Files, Sqlite, Redis and many other.
More information about using cache and configuration it you can find in this Wiki.
/** * Cache in system files */ $oFilesConfig = new \Phpfastcache\Drivers\Files\Config(); $oFilesConfig->setPath(sys_get_temp_dir())->setDefaultTtl(60); $oInstanceCacheFiles = new \Phpfastcache\Helper\Psr16Adapter('files', $oFilesConfig); /** * Cache in Redis */ $oRedisConfig = new \Phpfastcache\Drivers\Redis\Config(); $oRedisConfig ->setHost('localhost') ->setPort(6379) ->setDefaultTtl(60) ; $oInstanceCacheRedis = new \Phpfastcache\Helper\Psr16Adapter('redis', $oRedisConfig);
Log
Library also supports logging packages based on PSR-3 standard, i.e. very popular monolog/monolog.
$oInstanceLogger = new \Monolog\Logger('name_of_my_logger'); $oInstanceLogger->pushHandler(new \Monolog\Handler\ErrorLogHandler( \Monolog\Handler\ErrorLogHandler::OPERATING_SYSTEM, \Psr\Log\LogLevel::DEBUG ) )->pushProcessor(new \Monolog\Processor\PsrLogMessageProcessor());
External sources
GIOS
GIOS (Chief Inspectorate of Environmental Protection - Główny Inspektorat Ochrony Środowiska) provide API without any authentication.
Airly
Airly builds networks of air quality sensors that can be deployed across entire cities or counties. If you want to use external data using this API you have to get the free Token key from here .
OWM
Open Weather Map is well know project for weather and forecast. To use it, get the free Token Key from here .
API usage
Create instance
$oClient = new \mrcnpdlk\Weather\Client(); $oClient ->setCacheInstance($oInstanceCacheFiles) ->setLoggerInstance($oInstanceLogger) ->setAirlyConfig('AIRLY_TOKEN') // not required but recommended ->setOWMConfig('OWM_TOKEN') // not required but recommended ; $oApi = new \mrcnpdlk\Weather\Api($oClient);
By default API uses:
- current geo location found using public IP of machine where script is run
- current date of machine where script is run
We are able to change location calling setLocation() method.
use mrcnpdlk\Weather\NativeModel\GeoPoint; $oApi->setLocation(new GeoPoint(51.758158,19.544377));
Methods
| Name | Description | Uses external sources? |
|---|---|---|
| getAddress() | Getting address using revers geocode | no |
| getSunSchedule() | Getting surise, sunset, twilight timing etc | no |
| getNearestGiosStation() | Getting nearest GIOS station | no |
| getUVIndex() | UV Index | yes, OWM |
| getWeather() | weather | yes, OWM |
Examples
getAddress()
mrcnpdlk\Weather\Model\Address Object
(
[countryCode] => pl
[province] => łódzkie
[commune] => Łódź
[place] => Łódź
[neighbourhood] => Katedralna
[street] => Wincentego Tymienieckiego
[homeNr] => 16
[postalCode] => 90-365
)
getSunSchedule()
Method can give inappropriate results for location near pole.
mrcnpdlk\Weather\Model\SunSchedule Object
(
[sunrise] => 07:46:57
[sunset] => 15:50:12
[dayDuration] => 8:03
[transit] => 11:48:34
[civilTwilightBegin] => 07:07:27
[civilTwilightEnd] => 16:29:42
[nauticalTwilightBegin] => 06:24:41
[nauticalTwilightEnd] => 17:12:27
[astronomicalTwilightBegin] => 05:44:05
[astronomicalTwilightEnd] => 17:53:03
)
getUVIndex()
0.43
getNearestGiosStation()
mrcnpdlk\Weather\NativeModel\Gios\Station Object
(
[id] => 10058
[stationName] => Łódź-Jana Pawła II 15
[dateStart] => 2015-10-27 00:00:00
[dateEnd] =>
[gegrLat] => 51.754613
[gegrLon] => 19.434925
[addressStreet] => al. Jana Pawła II 15
[city] => mrcnpdlk\Weather\NativeModel\Gios\City Object
(
[id] => 516
[name] => Łódź
[commune] => mrcnpdlk\Weather\NativeModel\Gios\Commune Object
(
[communeName] => Łódź
[districtName] => Łódź
[provinceName] => ŁÓDZKIE
)
)
[distance] => 2253.495
)
mrcnpdlk\Weather\NativeModel\Gios\Station has implemented two methods:
| Name | Description |
|---|---|
| getAirQualityIndex() | Return air quality index |
| getSensors() | Return list of available sensors for station |
For each sensor getData() method return list of historical measurement data. |
Native API
mrcnpdlk/weather-api 适用场景与选型建议
mrcnpdlk/weather-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 01 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「weather」 「air quality」 「pogoda」 「airly」 「gios」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mrcnpdlk/weather-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrcnpdlk/weather-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mrcnpdlk/weather-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple tool for checking that your PHP classes and methods use PHPDocs (PHP DocBlocks Checker fork).
Simple PHP Wrapper for the World Air Quality Index API
Taptima PHP-CS-Fixer fixers
Static analyzer tool for PHP : Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more !
Extensible package of custom rules for PHPStan.
Laravel-forecast provides a service provider and a facade around the Forecast-php wrapper
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-07