pianosolo/weather-bundle
Composer 安装命令:
composer require pianosolo/weather-bundle
包简介
Weather Bundle of Symfony
README 文档
README
The PianoSolo Weather Bundle is a Symfony2 project to get data from weather services. Currently bringing data from OpenWeatherMap api. PianoSolo Weather Bundle has got different way of using the weather data in your project. One as a Twig Extension and the second one as a service which brings all weather information from api as object.
Installation
1-) Tell composer to download by running the command:
composer require pianosolo/weather-bundle
2-) Add the bundle to AppKernel
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new PianoSolo\WeatherBundle\PianoSoloWeatherBundle(), ); }
3-) Add configuration to config.yml file
piano_solo_weather: api_key: "YourApiKey" # Required (OpenWeatherMap Api Key) options: download_csv: false # Default True cache: true # Default False (To use cache the system needs Php-Apc cache)
To install Php-Apc rund this command:
sudo apt-get install php-apc
4-) Add the routing for CSV Downloading to routing.yml
pianosolo_weather: resource: "@PianoSoloWeatherBundle/Resources/config/routing.yml"
Usage
Basic Usage
Gets data from OpenWeatherMap api. Check api for usage: http://openweathermap.org/api
Get data with type. Add url parameters in array.
$weatherService = $this->get('pianosolo.weather'); $weather = $weatherService->getData('forecast', array('id' => 800, 'lat' => 52.52, 'lon' => 13.41));
Or get data with city name and type
$weatherService = $this->get('pianosolo.weather'); $weather = $weatherService->getCityData('weather', 'Berlin', array('param' => 'value'));
As Twig Extension
It brings the daily forecasts as html formatted in bootstrap table.
{{ pianosolo_get_forecast('Istanbul', 5) }}
This brings 5 days weather information of Istanbul ( Date, City, Temperature, Description )
{{ pianosolo_get_weather('Istanbul') }}
This brings 1 day of weather reasults of Istanbul ( Date, City, Temperature, Description )
As Weather Service
1-) Get weather response as stdclass object
$weatherService = $this->get('pianosolo.weather'); $weather = $weatherService->getWeather('Istanbul');
2-) Get weather as weather object
$weatherService = $this->get('pianosolo.weather'); $weathersArray = $weatherService->getWeatherObject('Istanbul'); $weatherObject = $weathersArray[0]; $city = $WeatherObject->getCity(); $date = $WeatherObject->getWdate(); $temperature = $WeatherObject->getTemperature(); $description = $WeatherObject->getDescription();
3-) Get forecast response as stdclass object
$weatherService = $this->get('pianosolo.weather'); $weather = $weatherService->getForecast('Istanbul', 2); // 2 days weather results of the city
4-) Get forecast as weather object array
$weatherService = $this->get('pianosolo.weather'); $weathersArray = $weatherService->getForecastObject('Istanbul',2); foreach($weathersArray as $weatherObject){ $city = $WeatherObject->getCity(); $date = $WeatherObject->getWdate(); $temperature = $WeatherObject->getTemperature(); $description = $WeatherObject->getDescription(); // Your Logic... }
pianosolo/weather-bundle 适用场景与选型建议
pianosolo/weather-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.47k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pianosolo/weather-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pianosolo/weather-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-12