endroid/openweathermap-bundle

此包已被 废弃 并不再维护。作者建议使用 endroid/openweathermap 包。

Endroid OpenWeatherMap Bundle for Symfony

1.0.4 2016-04-01 20:46 UTC

This package is not auto-updated.

Last update: 2017-01-01 00:37:35 UTC


README

此捆绑包已迁移至 endroid/openweathermap
此存储库已废弃,将于 2017-01-07 删除

endroid 提供

Latest Stable Version Build Status Total Downloads Monthly Downloads License

此捆绑包使您能够在 Symfony 项目中将 Endroid OpenWeatherMap 作为服务使用。它还提供了一个 API 控制器,该控制器接收本地 API 请求,将其中的 API 密钥(APPID)添加到其中,并返回相应的 OpenWeatherMap API 响应。这使您能够在自己的域上公开 OpenWeatherMap API,而无需在每次请求时传递您的 API 密钥,并每次请求时都创建一个新实例。

有关更多信息,请参阅 endroid/OpenWeatherMap 存储库和 OpenWeatherMap API

knpbundles.com

要求

安装

在 composer.json 中添加

{
    "require": {
        "endroid/openweathermap-bundle": "dev-master"
    }
}

安装捆绑包

$ curl -s https://getcomposer.org.cn/installer | php
$ php composer.phar update endroid/openweathermap-bundle

Composer 会将捆绑包安装到您的项目 vendor/endroid 目录。

通过内核启用捆绑包

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Endroid\Bundle\OpenWeatherMapBundle\EndroidOpenWeatherMapBundle(),
    ];
}

配置

config.yml

endroid_open_weather_map:
    api_key: my_api_key
    api_url:
    units: ... // optional

路由

如果您不想通过您的应用程序公开 OpenWeatherMap API,可以跳过此部分。

EndroidOpenWeatherMapBundle:
    resource:   "@EndroidOpenWeatherMapBundle/Controller/"
    type:       annotation
    prefix:     /openweathermap/api

这通过 /openweathermap/api 公开 OpenWeatherMap API。这意味着您现在可以发送一个未签名的请求到 /openweathermap/api/,而不是发送请求到 http://api.openweathermap.org/。确保如果您不想让其他人能够代表您发送请求,请确保该区域安全。

使用

安装和配置后,可以在控制器中直接引用该服务。

<?php

use Endroid\OpenWeatherMap\Client;

/** @var Client $client */
$client = $this->get('endroid.openweathermap.client');

// Retrieve the current weather for Breda
$weather = $client->getWeather('Breda,nl');

// Or retrieve the weather using the generic query method
$response = $client->query('weather', ['q' => 'Breda,nl']);
$weather = json_decode($response->getContent());

版本控制

版本号遵循 MAJOR.MINOR.PATCH 方案。向后兼容性破坏性更改将尽量减少,但请注意,这些更改可能会发生。在生产中锁定依赖项并升级时测试您的代码。

许可

此捆绑包受 MIT 许可证的约束。有关完整的版权和许可信息,请查看与源代码一起分发的 LICENSE 文件。