jeffbdn / tools-bundle
Symfony JeffBdnToolsBundle
0.0.1
2017-07-26 14:01 UTC
Requires
- php: >=5.6.0
- symfony/framework-bundle: ~2.3
- symfony/security-bundle: ~2.3
Requires (Dev)
- doctrine/doctrine-bundle: ~1.3
- symfony/validator: ~2.3
- symfony/yaml: ~2.3
- twig/twig: ~1.5
This package is not auto-updated.
Last update: 2024-09-29 04:20:14 UTC
README
步骤 1:下载 Bundle
打开命令行,进入您的项目目录,并执行以下命令以下载此 Bundle 的最新稳定版本
$ composer require jeffbdn/tools-bundle "~1"
此命令要求您全局安装 Composer,具体请参阅 Composer 文档中的 安装章节。
步骤 2:启用 Bundle
然后,通过将其添加到项目中 app/AppKernel.php 文件中注册的 Bundle 列表来启用该 Bundle
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new JeffBdn\ToolsBundle\JeffBdnToolsBundle(), ); // ... } // ... }
此 Bundle 包含几个服务。为了在项目中使用它们,请在您的 config.yml 中注册 Bundle 的 services.yml 文件
# app/config/config.yml imports: ... - { resource: "@JeffBdnToolsBundle/Resources/config/services.yml" }
然后,在您的 config.yml 中添加和自定义这些参数
# app/config/config.yml parameters: jeffbdn_tools.weather.apikey: 'PASTE HERE YOUR openweathermaps API KEY' jeffbdn_tools.weather.refresh: '3 minutes' # or 1 day or 2 days or 1 hour or 2 hours or 1 minute or 2 minutes
jeffbdn_tools.weather.apikey:为了使用天气服务,您需要一个 OpenWeatherMaps API 密钥。您可以在 https://home.openweathermap.org/users/sign_up 上创建新账户免费获得一个。
jeffbdn_tools.weather.refresh:您可以选择所有位置的广播刷新率。如果数据超过您指定的时间,则在下一次调用时刷新缓存。
步骤 3:使用工具
JeffBdnToolsBundle 的当前版本提供了 2 个服务
- 随机数提供者
$randomNumber = $this->get('jeffbdn_tools.math')->random();
- 天气广播提供者
$weatherBroadcast = $this->get('jeffbdn_tools.weather')->broadcast('Paris,fr');
您可能感兴趣使用的数据包括
- 开尔文、摄氏度、华氏度温度
$weatherBroadcast['temp_k'] $weatherBroadcast['temp_k_min'] $weatherBroadcast['temp_k_max']
$weatherBroadcast['temp_c'] $weatherBroadcast['temp_c'] $weatherBroadcast['temp_c_max']
$weatherBroadcast['temp_f'] $weatherBroadcast['temp_f_min'] $weatherBroadcast['temp_f_max']
- 天空和大气细节
$weatherBroadcast['humidity'] $weatherBroadcast['sky_description_short'] $weatherBroadcast['sky_description_long'] $weatherBroadcast['pressure_hpa'] $weatherBroadcast['wind_speed_metersec'] $weatherBroadcast['cloud_percent']
- 最后更新日期、日出和日落时间
$weatherBroadcast['date'] $weatherBroadcast['sunrise'] $weatherBroadcast['sunset']
- 错误管理
// true if API call went well, else false $weatherBroadcast['ok'] // this is the HTTP response code, default is 200 $weatherBroadcast['error_code'] // this is the API response message, default is an empty string $weatherBroadcast['error_string']
步骤 4:测试 ToolsBundle
$ phpunit vendor/jeffbdn/tools-bundle/JeffBdn/ToolsBundle/Tests/Weather.php
如果遇到任何错误,请在 http://www.github.com/jeffbdn/tools-bundle/issues 上报告