nwidart / laravel-forecast
Laravel-forecast 提供了一个服务提供者和 Forecast-php 封装的包装
2.1
2015-08-02 14:53 UTC
Requires
- php: >=5.5.0
- illuminate/support: ~5.1
- nwidart/forecast-php: ~1.0
README
Laravel 5 兼容的包
Laravel-Forecast
Laravel-forecast 提供了一个服务提供者和围绕 Forecast-php 封装的包装。
想要将其作为独立包使用?请查看 Forecast-php API 封装。
安装
$ composer require nwidart/laravel-forecast
在 app/config/app.php
中添加服务提供者
'providers' => [ ... Nwidart\LaravelForecast\LaravelForecastServiceProvider::class ]
在 app/config/app.php
中添加别名提供者
'aliases' => [ ... 'Forecast' => Nwidart\LaravelForecast\ForecastFacade::class, ]
发布配置文件并添加您的 forecast API 密钥
$ php artisan vendor:publish --provider="Nwidart\LaravelForecast\LaravelForecastServiceProvider"
使用方法
基本使用
<?php Forecast::get('37.8267','-122.423'); // Get the forecast at a given time Forecast::get(('37.8267','-122.423', '2013-05-06T12:00:00-0400')
为每个请求设置全局选项
在设置中,您可以添加将在向 Forecast.io 发出的每个请求上使用的全局选项。您可以在设置文件的 options
键中添加这些。
例如,如果您想使用摄氏度表示温度
'options' => [ 'units' => 'si', ],
有关更多详细信息以及所有可用选项,请查看 官方文档。
替代方法:依赖注入
您还可以将 Nwidart\ForecastPhp\Forecast
类注入到您的构造函数中。
/** * @var \Nwidart\ForecastPhp\Forecast */ private $forecast; public function __construct(\Nwidart\ForecastPhp\Forecast $forecast) { $this->forecast = $forecast; } public function doSomething() { $weather = $this->forecast->get($lat, $lon); }