th3mouk / yahoo-weather-bundle
包含 Yahoo 天气 API 并在数据库中存档数据的 Symfony 扩展包。
0.9
2016-04-21 13:33 UTC
Requires
- php: ^5.4|^7.0
- gedmo/doctrine-extensions: ^2.3.12
- symfony/config: ~2.3
- symfony/console: ~2.3
- symfony/dependency-injection: ~2.3
- symfony/http-kernel: ~2.3
- th3mouk/yahoo-weather-api: ^1.0@dev
- twig/twig: ^1.12
Requires (Dev)
- fabpot/php-cs-fixer: ^0.5|^1.0
- symfony/phpunit-bridge: ~2.7|~3.0
This package is auto-updated.
Last update: 2024-08-26 02:10:21 UTC
README
这个 Symfony 扩展包提供了 Yahoo 天气 API 的通信和历史记录。
安装
composer require th3mouk/yahoo-weather-bundle ^1.0@dev
添加到 appKernel.php
// Weather Bundle new Th3Mouk\YahooWeatherBundle\Th3MoukYahooWeatherBundle(),
完整的 config.yml
配置
th3mouk_yahoo_weather: templates: today: Th3MoukYahooWeatherBundle:Default:today.html.twig forecast: Th3MoukYahooWeatherBundle:Default:forecast.html.twig pictograms: helper: ImplementsYourOwn extension: Th3Mouk\YahooWeatherBundle\Twig\PictoExtension
用法
此扩展包提供了两个实体:Th3Mouk\YahooWeatherBundle\Entity\City
和 Th3Mouk\YahooWeatherBundle\Entity\Forecast
。
第一个是与 API 的通信相关的,城市对象必须具有 Yahoo 天气文档中指定的城市名称或 WOEID 码。第二个用于数据持久化和历史检索。
扩展它们或随意修改!
Twig 扩展
天气
您有两个扩展来绘制预报,它们使用配置中定义的模板。随意实现或添加您自己的!
{{ weather_forecast(city, unit = 'c') }} {{ weather_today(city, unit = 'c') }}
图标
您可以在配置中添加一个 pictogram 辅助工具以激活此扩展,该扩展必须实现 Th3Mouk\YahooWeatherBundle\Helper\PictogramInterface
。
{{ code|weather_pictogram }}
这是一个 PictogramHelper 的示例
namespace AppBundle\Helper; use Th3Mouk\YahooWeatherBundle\Helper\PictogramInterface; class WeatherPictogramHelper implements PictogramInterface { /** * Function that retrieve the html string corresponding to a weather code. * * @param $code * * @return string|null */ public function getPictogram($code) { return "<img src='favicon.ico'/>"; } }
Sonata 集成示例
此扩展包自动提供城市的管理。
服务名称为 th3mouk_yahoo_weather.admin.city
。
th3mouk_yahoo_weather.admin.city: class: Th3Mouk\YahooWeatherBundle\Admin\CityAdmin arguments: [~, Th3Mouk\YahooWeatherBundle\Entity\City, SonataAdminBundle:CRUD] tags: - {name: sonata.admin, manager_type: orm, group: weather, label: city}
在仪表板上添加管理员组
sonata.admin.group.weather: label: weather label_catalogue: messages icon: '<i class="fa fa-sun-o"></i>' items: - th3mouk_yahoo_weather.admin.city roles: [ ROLE_ADMIN ]
别忘了在块中添加此组
sonata_admin: dashboard: blocks: - { position: left, type: sonata.admin.block.admin_list, settings: { groups: [...sonata.admin.group.weather...] }}
完成了!👍
待办事项
- 在天气 twig 扩展中添加模板选项
- 添加不带城市对象的今日预报
- 从扩展包中移除 sonata 配置
- 添加天气扩展配置
- 添加历史记录的 twig 扩展
- 添加天气比较(今天和 Y-1)的 twig 扩展
- 添加天气比较(预报和 Y-1)的 twig 扩展
请
随意改进此扩展包。