Revert "added composer.json and needed libs"

This reverts commit 1f74d409a2.
This commit is contained in:
Tobias Diekershoff 2015-07-13 09:13:54 +02:00
parent c02fef3e1f
commit 0d31af52ea
42 changed files with 0 additions and 4413 deletions

View File

@ -1,5 +0,0 @@
{
"require": {
"cmfcmf/openweathermap-php-api": "~2.0"
}
}

View File

@ -1,7 +0,0 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit6bf0e42f34a65c53928f3dc22e5b93d3::getLoader();

View File

@ -1 +0,0 @@
/vendor

View File

@ -1,22 +0,0 @@
language: php
sudo: false
php:
- 5.3
- 5.4
- 5.5
- 5.6
- hhvm
- nightly
matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: nightly
install:
- composer install --dev
script: phpunit

View File

@ -1,598 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf;
use Cmfcmf\OpenWeatherMap\AbstractCache;
use Cmfcmf\OpenWeatherMap\CurrentWeather;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
use Cmfcmf\OpenWeatherMap\Fetcher\CurlFetcher;
use Cmfcmf\OpenWeatherMap\Fetcher\FetcherInterface;
use Cmfcmf\OpenWeatherMap\Fetcher\FileGetContentsFetcher;
use Cmfcmf\OpenWeatherMap\WeatherForecast;
use Cmfcmf\OpenWeatherMap\WeatherHistory;
/**
* Main class for the OpenWeatherMap-PHP-API. Only use this class.
*
* @api
*/
class OpenWeatherMap
{
/**
* @var string $weatherUrl The basic api url to fetch weather data from.
*/
private $weatherUrl = "http://api.openweathermap.org/data/2.5/weather?";
/**
* @var string $url The basic api url to fetch weekly forecast data from.
*/
private $weatherHourlyForecastUrl = "http://api.openweathermap.org/data/2.5/forecast?";
/**
* @var string $url The basic api url to fetch daily forecast data from.
*/
private $weatherDailyForecastUrl = "http://api.openweathermap.org/data/2.5/forecast/daily?";
/**
* @var string $url The basic api url to fetch history weather data from.
*/
private $weatherHistoryUrl = "http://api.openweathermap.org/data/2.5/history/city?";
/**
* The copyright notice. This is no official text, this hint was created regarding to http://openweathermap.org/copyright.
*
* @var string $copyright
*/
const COPYRIGHT = "Weather data from <a href=\"http://www.openweathermap.org\">OpenWeatherMap.org</a>";
/**
* @var \Cmfcmf\OpenWeatherMap\AbstractCache|bool $cacheClass The cache class.
*/
private $cacheClass = false;
/**
* @var int
*/
private $seconds;
/**
* @var FetcherInterface The url fetcher.
*/
private $fetcher;
/**
* Constructs the OpenWeatherMap object.
*
* @param null|FetcherInterface $fetcher The interface to fetch the data from OpenWeatherMap. Defaults to
* CurlFetcher() if cURL is available. Otherwise defaults to
* FileGetContentsFetcher() using 'file_get_contents()'.
* @param bool|string $cacheClass If set to false, caching is disabled. Otherwise this must be a class
* extending AbstractCache. Defaults to false.
* @param int $seconds How long weather data shall be cached. Default 10 minutes.
*
* @throws \Exception If $cache is neither false nor a valid callable extending Cmfcmf\OpenWeatherMap\Util\Cache.
* @api
*/
public function __construct($fetcher = null, $cacheClass = false, $seconds = 600)
{
if ($cacheClass !== false && !($cacheClass instanceof AbstractCache)) {
throw new \Exception("The cache class must implement the FetcherInterface!");
}
if (!is_numeric($seconds)) {
throw new \Exception("\$seconds must be numeric.");
}
if (!isset($fetcher)) {
$fetcher = (function_exists('curl_version')) ? new CurlFetcher() : new FileGetContentsFetcher();
}
if ($seconds == 0) {
$cacheClass = false;
}
$this->cacheClass = $cacheClass;
$this->seconds = $seconds;
$this->fetcher = $fetcher;
}
/**
* Returns the current weather at the place you specified as an object.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
*
* @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error.
* @throws \InvalidArgumentException If an argument error occurs.
*
* @return CurrentWeather The weather object.
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getWeather($query, $units = 'imperial', $lang = 'en', $appid = '')
{
// Disable default error handling of SimpleXML (Do not throw E_WARNINGs).
libxml_use_internal_errors(true);
libxml_clear_errors();
$answer = $this->getRawWeatherData($query, $units, $lang, $appid, 'xml');
try {
$xml = new \SimpleXMLElement($answer);
} catch (\Exception $e) {
// Invalid xml format. This happens in case OpenWeatherMap returns an error.
// OpenWeatherMap always uses json for errors, even if one specifies xml as format.
$error = json_decode($answer, true);
if (isset($error['message'])) {
throw new OWMException($error['message'], $error['cod']);
} else {
throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer);
}
}
return new CurrentWeather($xml, $units);
}
/**
* Returns the current weather at the place you specified as an object.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
* @param int $days For how much days you want to get a forecast. Default 1, maximum: 16.
*
* @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error.
* @throws \InvalidArgumentException If an argument error occurs.
*
* @return WeatherForecast The WeatherForecast object.
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getWeatherForecast($query, $units = 'imperial', $lang = 'en', $appid = '', $days = 1)
{
// Disable default error handling of SimpleXML (Do not throw E_WARNINGs).
libxml_use_internal_errors(true);
libxml_clear_errors();
if ($days <= 5) {
$answer = $this->getRawHourlyForecastData($query, $units, $lang, $appid, 'xml');
} else if ($days <= 16) {
$answer = $this->getRawDailyForecastData($query, $units, $lang, $appid, 'xml', $days);
} else {
throw new \InvalidArgumentException('Error: forecasts are only available for the next 16 days. $days must be lower than 17.');
}
try {
$xml = new \SimpleXMLElement($answer);
} catch (\Exception $e) {
// Invalid xml format. This happens in case OpenWeatherMap returns an error.
// OpenWeatherMap always uses json for errors, even if one specifies xml as format.
$error = json_decode($answer, true);
if (isset($error['message'])) {
throw new OWMException($error['message'], $error['cod']);
} else {
throw new OWMException('Unknown fatal error: OpenWeatherMap returned the following json object: ' . $answer);
}
}
return new WeatherForecast($xml, $units, $days);
}
/**
* Returns the weather history for the place you specified as an object.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param \DateTime $start
* @param int $endOrCount
* @param string $type
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
*
* @throws OpenWeatherMap\Exception If OpenWeatherMap returns an error.
* @throws \InvalidArgumentException If an argument error occurs.
*
* @return WeatherHistory The WeatherHistory object.
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '')
{
if (!in_array($type, array('tick', 'hour', 'day'))) {
throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"');
}
$xml = json_decode($this->getRawWeatherHistory($query, $start, $endOrCount, $type, $units, $lang, $appid), true);
if ($xml['cod'] != 200) {
throw new OWMException($xml['message'], $xml['cod']);
}
return new WeatherHistory($xml, $query);
}
/**
* @deprecated Use {@link self::getRawWeatherData()} instead.
*/
public function getRawData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml')
{
return $this->getRawWeatherData($query, $units, $lang, $appid, $mode);
}
/**
* Directly returns the xml/json/html string returned by OpenWeatherMap for the current weather.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
*
* @return string Returns false on failure and the fetched data in the format you specified on success.
*
* Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getRawWeatherData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml')
{
$url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherUrl);
return $this->cacheOrFetchResult($url);
}
/**
* Directly returns the xml/json/html string returned by OpenWeatherMap for the hourly forecast.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default).
*
* @return string Returns false on failure and the fetched data in the format you specified on success.
*
* Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getRawHourlyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml')
{
$url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherHourlyForecastUrl);
return $this->cacheOrFetchResult($url);
}
/**
* Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
* @param string $mode The format of the data fetched. Possible values are 'json', 'html' and 'xml' (default)
* @param int $cnt How many days of forecast shall be returned? Maximum (and default): 16
*
* @throws \InvalidArgumentException If $cnt is higher than 16.
* @return string Returns false on failure and the fetched data in the format you specified on success.
*
* Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getRawDailyForecastData($query, $units = 'imperial', $lang = 'en', $appid = '', $mode = 'xml', $cnt = 16)
{
if ($cnt > 16) {
throw new \InvalidArgumentException('$cnt must be 16 or below!');
}
$url = $this->buildUrl($query, $units, $lang, $appid, $mode, $this->weatherDailyForecastUrl) . "&cnt=$cnt";
return $this->cacheOrFetchResult($url);
}
/**
* Directly returns the xml/json/html string returned by OpenWeatherMap for the daily forecast.
*
* @param array|int|string $query The place to get weather information for. For possible values see below.
* @param \DateTime $start The \DateTime object of the date to get the first weather information from.
* @param \DateTime|int $endOrCount Can be either a \DateTime object representing the end of the period to
* receive weather history data for or an integer counting the number of
* reports requested.
* @param string $type The period of the weather history requested. Can be either be either "tick",
* "hour" or "day".
* @param string $units Can be either 'metric' or 'imperial' (default). This affects almost all units returned.
* @param string $lang The language to use for descriptions, default is 'en'. For possible values see below.
* @param string $appid Your app id, default ''. See http://openweathermap.org/appid for more details.
*
* @throws \InvalidArgumentException
*
* @return string Returns false on failure and the fetched data in the format you specified on success.
*
* Warning If an error occurred, OpenWeatherMap returns data in json format ALWAYS
*
* There are three ways to specify the place to get weather information for:
* - Use the city name: $query must be a string containing the city name.
* - Use the city id: $query must be an integer containing the city id.
* - Use the coordinates: $query must be an associative array containing the 'lat' and 'lon' values.
*
* Available languages are (as of 17. July 2013):
* - English - en
* - Russian - ru
* - Italian - it
* - Spanish - sp
* - Ukrainian - ua
* - German - de
* - Portuguese - pt
* - Romanian - ro
* - Polish - pl
* - Finnish - fi
* - Dutch - nl
* - French - fr
* - Bulgarian - bg
* - Swedish - se
* - Chinese Traditional - zh_tw
* - Chinese Simplified - zh_cn
* - Turkish - tr
*
* @api
*/
public function getRawWeatherHistory($query, \DateTime $start, $endOrCount = 1, $type = 'hour', $units = 'imperial', $lang = 'en', $appid = '')
{
if (!in_array($type, array('tick', 'hour', 'day'))) {
throw new \InvalidArgumentException('$type must be either "tick", "hour" or "day"');
}
$queryUrl = $this->weatherHistoryUrl . $this->buildQueryUrlParameter($query) . "&start={$start->format('U')}";
if ($endOrCount instanceof \DateTime) {
$queryUrl .= "&end={$endOrCount->format('U')}";
} else if (is_numeric($endOrCount) && $endOrCount > 0) {
$queryUrl .= "&cnt=$endOrCount";
} else {
throw new \InvalidArgumentException('$endOrCount must be either a \DateTime or a positive integer.');
}
$queryUrl .= "&type=$type&units=$units&lang=$lang";
if (!empty($appid)) {
$queryUrl .= "&APPID=$appid";
}
return $this->cacheOrFetchResult($queryUrl);
}
/**
* Fetches the result or delivers a cached version of the result.
*
* @param $url
*
* @return string
*
* @internal
*/
private function cacheOrFetchResult($url)
{
if ($this->cacheClass !== false) {
/** @var \Cmfcmf\OpenWeatherMap\AbstractCache $cache */
$cache = $this->cacheClass;
$cache->setSeconds($this->seconds);
if ($cache->isCached($url)) {
return $cache->getCached($url);
}
$result = $this->fetcher->fetch($url);
$cache->setCached($url, $result);
} else {
$result = $this->fetcher->fetch($url);
}
return $result;
}
/**
* Build the url to fetch weather data from.
*
* @param $query
* @param $units
* @param $lang
* @param $appid
* @param $mode
* @param string $url The url to prepend.
*
* @return bool|string The fetched url, false on failure.
*
* @internal
*/
private function buildUrl($query, $units, $lang, $appid, $mode, $url)
{
$queryUrl = $this->buildQueryUrlParameter($query);
$url = $url . "$queryUrl&units=$units&lang=$lang&mode=$mode";
if (!empty($appid)) {
$url .= "&APPID=$appid";
}
return $url;
}
/**
* Builds the query string for the url.
*
* @param $query
*
* @return string The built query string for the url.
* @throws \InvalidArgumentException If the query parameter is invalid.
*
* @internal
*/
private function buildQueryUrlParameter($query)
{
switch ($query) {
case (is_array($query) && isset($query['lat']) && isset($query['lon']) && is_numeric($query['lat']) && is_numeric($query['lon'])):
return "lat={$query['lat']}&lon={$query['lon']}";
case (is_numeric($query)):
return "id=$query";
case (is_string($query)):
return "q=" . urlencode($query);
default:
throw new \InvalidArgumentException('Error: $query has the wrong format. See the documentation of OpenWeatherMap::getRawData() to read about valid formats.');
}
}
}

View File

@ -1,69 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
/**
* Abstract cache class to be overwritten by custom cache implementations.
*/
abstract class AbstractCache
{
/**
* @var int $seconds Cache time in seconds.
*/
protected $seconds;
/**
* Checks whether a cached weather data is available.
*
* @param string $url The unique url of the cached content.
*
* @return bool False if no cached information is available, otherwise true.
*
* You need to check if a cached result is outdated here. Return false in that case.
*/
abstract public function isCached($url);
/**
* Returns cached weather data.
*
* @param string $url The unique url of the cached content.
*
* @return string|bool The cached data if it exists, false otherwise.
*/
abstract public function getCached($url);
/**
* Saves cached weather data.
*
* @param string $url The unique url of the cached content.
* @param string $content The weather data to cache.
*
* @return bool True on success, false on failure.
*/
abstract public function setCached($url, $content);
/**
* Set after how much seconds the cache shall expire.
*
* @param int $seconds
*/
public function setSeconds($seconds)
{
$this->seconds = $seconds;
}
}

View File

@ -1,117 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Util\City;
use Cmfcmf\OpenWeatherMap\Util\Sun;
use Cmfcmf\OpenWeatherMap\Util\Temperature;
use Cmfcmf\OpenWeatherMap\Util\Unit;
use Cmfcmf\OpenWeatherMap\Util\Weather as WeatherObj;
use Cmfcmf\OpenWeatherMap\Util\Wind;
/**
* Weather class used to hold the current weather data.
*/
class CurrentWeather
{
/**
* The city object.
*
* @var Util\City
*/
public $city;
/**
* The temperature object.
*
* @var Util\Temperature
*/
public $temperature;
/**
* @var Util\Unit
*/
public $humidity;
/**
* @var Util\Unit
*/
public $pressure;
/**
* @var Util\Wind
*/
public $wind;
/**
* @var Util\Unit
*/
public $clouds;
/**
* @var Util\Unit
*/
public $precipitation;
/**
* @var Util\Sun
*/
public $sun;
/**
* @var Util\Weather
*/
public $weather;
/**
* @var \DateTime
*/
public $lastUpdate;
/**
* Create a new weather object.
*
* @param \SimpleXMLElement $xml
* @param string $units
*
* @internal
*/
public function __construct(\SimpleXMLElement $xml, $units)
{
$this->city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country);
$this->temperature = new Temperature(new Unit($xml->temperature['value'], $xml->temperature['unit']), new Unit($xml->temperature['min'], $xml->temperature['unit']), new Unit($xml->temperature['max'], $xml->temperature['unit']));
$this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']);
$this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']);
// This is kind of a hack, because the units are missing in the xml document.
if ($units == 'metric') {
$windSpeedUnit = 'm/s';
} else {
$windSpeedUnit = 'mph';
}
$this->wind = new Wind(new Unit($xml->wind->speed['value'], $windSpeedUnit, $xml->wind->speed['name']), new Unit($xml->wind->direction['value'], $xml->wind->direction['code'], $xml->wind->direction['name']));
$this->clouds = new Unit($xml->clouds['value'], null, $xml->clouds['name']);
$this->precipitation = new Unit($xml->precipitation['value'], $xml->precipitation['unit'], $xml->precipitation['mode']);
$utctz = new \DateTimeZone('UTC');
$this->sun = new Sun(new \DateTime($xml->city->sun['rise'], $utctz), new \DateTime($xml->city->sun['set'], $utctz));
$this->weather = new WeatherObj($xml->weather['number'], $xml->weather['value'], $xml->weather['icon']);
$this->lastUpdate = new \DateTime($xml->lastupdate['value'], $utctz);
}
}

View File

@ -1,27 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
/**
* Dummy class extending \Exception to allow checking if it is an OpenWeatherMap error
* or an argument error.
*/
class Exception extends \Exception
{
}

View File

@ -1,42 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Fetcher;
/**
* Class CurlFetcher.
*
* @internal
*/
class CurlFetcher implements FetcherInterface
{
/**
* {@inheritdoc}
*/
public function fetch($url)
{
$ch = curl_init($url);
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
}

View File

@ -1,37 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Fetcher;
/**
* Interface FetcherInterface.
*
* @api
*/
interface FetcherInterface
{
/**
* Fetch contents from the specified url.
*
* @param string $url The url to be fetched.
*
* @return string The fetched content.
*
* @api
*/
public function fetch($url);
}

View File

@ -1,34 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Fetcher;
/**
* Class FileGetContentsFetcher.
*
* @internal
*/
class FileGetContentsFetcher implements FetcherInterface
{
/**
* {@inheritdoc}
*/
public function fetch($url)
{
return file_get_contents($url);
}
}

View File

@ -1,83 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Util\City;
use Cmfcmf\OpenWeatherMap\Util\Sun;
use Cmfcmf\OpenWeatherMap\Util\Temperature;
use Cmfcmf\OpenWeatherMap\Util\Time;
use Cmfcmf\OpenWeatherMap\Util\Unit;
use Cmfcmf\OpenWeatherMap\Util\Weather as WeatherObj;
use Cmfcmf\OpenWeatherMap\Util\Wind;
/**
* Class Forecast.
*/
class Forecast extends CurrentWeather
{
/**
* @var Time The time of the forecast.
*/
public $time;
/**
* Create a new weather object for forecasts.
*
* @param \SimpleXMLElement $xml The forecasts xml.
* @param string $units Ths units used.
*
* @internal
*/
public function __construct(\SimpleXMLElement $xml, $units)
{
$this->city = new City($xml->city['id'], $xml->city['name'], $xml->city->coord['lon'], $xml->city->coord['lat'], $xml->city->country);
if ($units == 'metric') {
$temperatureUnit = "&deg;C";
} else {
$temperatureUnit = 'F';
}
$xml->temperature['value'] = ($xml->temperature['max'] + $xml->temperature['min']) / 2;
$this->temperature = new Temperature(new Unit($xml->temperature['value'], $temperatureUnit), new Unit($xml->temperature['min'], $temperatureUnit), new Unit($xml->temperature['max'], $temperatureUnit));
$this->humidity = new Unit($xml->humidity['value'], $xml->humidity['unit']);
$this->pressure = new Unit($xml->pressure['value'], $xml->pressure['unit']);
// This is kind of a hack, because the units are missing in the xml document.
if ($units == 'metric') {
$windSpeedUnit = 'm/s';
} else {
$windSpeedUnit = 'mps';
}
$this->wind = new Wind(new Unit($xml->windSpeed['mps'], $windSpeedUnit, $xml->windSpeed['name']), new Unit($xml->windDirection['value'], $xml->windDirection['code'], $xml->windDirection['name']));
$this->clouds = new Unit($xml->clouds['all'], $xml->clouds['unit'], $xml->clouds['value']);
$this->precipitation = new Unit($xml->precipitation['value'], null, $xml->precipitation['type']);
$this->sun = new Sun(new \DateTime($xml->city->sun['rise']), new \DateTime($xml->city->sun['set']));
$this->weather = new WeatherObj($xml->symbol['number'], $xml->symbol['name'], $xml->symbol['var']);
$this->lastUpdate = new \DateTime($xml->lastupdate['value']);
if (isset($xml['from'])) {
$this->time = new Time($xml['from'], $xml['to']);
} else {
$this->time = new Time($xml['day']);
}
}
}

View File

@ -1,104 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Util\Temperature;
use Cmfcmf\OpenWeatherMap\Util\Unit;
use Cmfcmf\OpenWeatherMap\Util\Weather;
use Cmfcmf\OpenWeatherMap\Util\Wind;
/**
* Class WeatherHistory.
*/
class History
{
/**
* The city object.
*
* @var Util\City
*/
public $city;
/**
* The temperature object.
*
* @var Util\Temperature
*/
public $temperature;
/**
* @var Util\Unit
*/
public $humidity;
/**
* @var Util\Unit
*/
public $pressure;
/**
* @var Util\Wind
*/
public $wind;
/**
* @var Util\Unit
*/
public $clouds;
/**
* @var Util\Unit
*/
public $precipitation;
/**
* @var Util\Weather
*/
public $weather;
/**
* @var \DateTime The time of the history.
*/
public $time;
/**
* @param $city
* @param $weather
* @param $temperature
* @param $pressure
* @param $humidity
* @param $clouds
* @param $rain
* @param $wind
* @param $time
*
* @internal
*/
public function __construct($city, $weather, $temperature, $pressure, $humidity, $clouds, $rain, $wind, $time)
{
$this->city = $city;
$this->weather = new Weather($weather['id'], $weather['description'], $weather['icon']);
$this->temperature = new Temperature(new Unit($temperature['now'] - 273.15, "\xB0C"), new Unit($temperature['min'] - 273.15, "\xB0C"), new Unit($temperature['max'] - 273.15, "\xB0C"));
$this->pressure = new Unit($pressure, 'kPa');
$this->humidity = new Unit($humidity, '%');
$this->clouds = new Unit($clouds, '%');
$this->precipitation = new Unit($rain['val'], $rain['unit']);
$this->wind = new Wind(new Unit($wind['speed']), new Unit($wind['deg']));
$this->time = $time;
}
}

View File

@ -1,76 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The city class representing a city object.
*/
class City
{
/**
* @var int The city id.
*/
public $id;
/**
* @var string The name of the city.
*/
public $name;
/**
* @var float The longitude of the city.
*/
public $lon;
/**
* @var float The latitude of the city.
*/
public $lat;
/**
* @var string The abbreviation of the country the city is located in.
*/
public $country;
/**
* @var int The city's population
*/
public $population;
/**
* Create a new city object.
*
* @param int $id The city id.
* @param string $name The name of the city.
* @param float $lon The longitude of the city.
* @param float $lat The latitude of the city.
* @param string $country The abbreviation of the country the city is located in
* @param int $population The city's population.
*
* @internal
*/
public function __construct($id, $name = null, $lon = null, $lat = null, $country = null, $population = null)
{
$this->id = (int)$id;
$this->name = isset($name) ? (string)$name : null;
$this->lon = isset($lon) ? (float)$lon : null;
$this->lat = isset($lat) ? (float)$lat : null;
$this->country = isset($country) ? (string)$country : null;
$this->population = isset($population) ? (int)$population : null;
}
}

View File

@ -1,52 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The sun class representing a sun object.
*/
class Sun
{
/**
* @var \DateTime The time of the sun rise.
*/
public $rise;
/**
* @var \DateTime The time of the sun set.
*/
public $set;
/**
* Create a new sun object.
*
* @param \DateTime $rise The time of the sun rise
* @param \DateTime $set The time of the sun set.
*
* @throws \LogicException If sunset is before sunrise.
* @internal
*/
public function __construct(\DateTime $rise, \DateTime $set)
{
if ($set < $rise) {
throw new \LogicException('Sunset cannot be before sunrise!');
}
$this->rise = $rise;
$this->set = $set;
}
}

View File

@ -1,105 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The temperature class representing a temperature object.
*/
class Temperature
{
/**
* @var Unit The current temperature.
*/
public $now;
/**
* @var Unit The minimal temperature.
*/
public $min;
/**
* @var Unit The maximal temperature.
*/
public $max;
/**
* Returns the current temperature as formatted string.
*
* @return string The current temperature as a formatted string.
*/
public function __toString()
{
return $this->now->__toString();
}
/**
* Returns the current temperature's unit.
*
* @return string The current temperature's unit.
*/
public function getUnit()
{
return $this->now->getUnit();
}
/**
* Returns the current temperature.
*
* @return string The current temperature.
*/
public function getValue()
{
return $this->now->getValue();
}
/**
* Returns the current temperature's description.
*
* @return string The current temperature's description.
*/
public function getDescription()
{
return $this->now->getDescription();
}
/**
* Returns the current temperature as formatted string.
*
* @return string The current temperature as formatted string.
*/
public function getFormatted()
{
return $this->now->getFormatted();
}
/**
* Create a new temperature object.
*
* @param Unit $now The current temperature.
* @param Unit $min The minimal temperature.
* @param Unit $max The maximal temperature.
*
* @internal
*/
public function __construct(Unit $now, Unit $min, Unit $max)
{
$this->now = $now;
$this->min = $min;
$this->max = $max;
}
}

View File

@ -1,65 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The time class representing a time object.
*/
class Time
{
/**
* @var \DateTime The start time for the forecast.
*/
public $from;
/**
* @var \DateTime The end time for the forecast.
*/
public $to;
/**
* @var \DateTime The day of the forecast.
*/
public $day;
/**
* Create a new time object.
*
* @param string|\DateTime $from The start time for the forecast.
* @param string|\DateTime $to The end time for the forecast.
*
* @internal
*/
public function __construct($from, $to = null)
{
if (isset($to)) {
$from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
$to = ($to instanceof \DateTime) ? $to : new \DateTime((string)$to);
$day = new \DateTime($from->format('Y-m-d'));
} else {
$from = ($from instanceof \DateTime) ? $from : new \DateTime((string)$from);
$day = clone $from;
$to = clone $from;
$to = $to->add(new \DateInterval('PT23H59M59S'));
}
$this->from = $from;
$this->to = $to;
$this->day = $day;
}
}

View File

@ -1,128 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The unit class representing a unit object.
*/
class Unit
{
/**
* @var float The value.
*
* @internal
*/
private $value;
/**
* @var string The value's unit.
*
* @internal
*/
private $unit;
/**
* @var string The value's description.
*
* @internal
*/
private $description;
/**
* Create a new unit object.
*
* @param float $value The value.
* @param string $unit The unit of the value.
* @param string $description The description of the value.
*
* @internal
*/
public function __construct($value = 0.0, $unit = "", $description = "")
{
$this->value = (float)$value;
$this->unit = (string)$unit;
$this->description = (string)$description;
}
/**
* Get the value as formatted string with unit.
*
* @return string The value as formatted string with unit.
*
* The unit is not included if it is empty.
*/
public function __toString()
{
return $this->getFormatted();
}
/**
* Get the value's unit.
*
* @return string The value's unit.
*
* This also converts 'celsius' to '°C' and 'fahrenheit' to 'F'.
*/
public function getUnit()
{
// Units are inconsistent. Only celsius and fahrenheit are not abbreviated. This check fixes that.
if ($this->unit == 'celsius') {
return "&deg;C";
} else if ($this->unit == 'fahrenheit') {
return 'F';
} else {
return $this->unit;
}
}
/**
* Get the value.
*
* @return float The value.
*/
public function getValue()
{
return $this->value;
}
/**
* Get the value's description.
*
* @return string The value's description.
*/
public function getDescription()
{
return $this->description;
}
/**
* Get the value as formatted string with unit.
*
* @return string The value as formatted string with unit.
*
* The unit is not included if it is empty.
*/
public function getFormatted()
{
if ($this->getUnit() != "") {
return "{$this->getValue()} {$this->getUnit()}";
} else {
return "{$this->getValue()}";
}
}
}

View File

@ -1,82 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The weather class representing a weather object.
*/
class Weather
{
/**
* @var int The weather id.
*/
public $id;
/**
* @var string The weather description.
*/
public $description;
/**
* @var string the icon name.
*/
public $icon;
/**
* @var string The url for icons.
*
* @see self::getIconUrl() to see how it is used.
*/
private $iconUrl = "http://openweathermap.org/img/w/%s.png";
/**
* Create a new weather object.
*
* @param int $id The icon id.
* @param string $description The weather description.
* @param string $icon The icon name.
*
* @internal
*/
public function __construct($id, $description, $icon)
{
$this->id = (int)$id;
$this->description = (string)$description;
$this->icon = (string)$icon;
}
/**
* Get the weather description.
*
* @return string
*/
public function __toString()
{
return $this->description;
}
/**
* Get the icon url.
*
* @return string The icon url.
*/
public function getIconUrl()
{
return str_replace("%s", $this->icon, $this->iconUrl);
}
}

View File

@ -1,48 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Util;
/**
* The wind class representing a wind object.
*/
class Wind
{
/**
* @var Unit The wind speed.
*/
public $speed;
/**
* @var Unit The wind direction.
*/
public $direction;
/**
* Create a new wind object.
*
* @param Unit $speed The wind speed.
* @param Unit $direction The wind direction.
*
* @internal
*/
public function __construct(Unit $speed, Unit $direction)
{
$this->speed = $speed;
$this->direction = $direction;
}
}

View File

@ -1,136 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Util\City;
use Cmfcmf\OpenWeatherMap\Util\Sun;
/**
* Weather class returned by Cmfcmf\OpenWeatherMap->getWeather().
*
* @see Cmfcmf\OpenWeatherMap::getWeather() The function using it.
*/
class WeatherForecast implements \Iterator
{
/**
* A city object.
*
* @var Util\City
*/
public $city;
/**
* A sun object
*
* @var Util\Sun
*/
public $sun;
/**
* The time of the last update of this weather data.
*
* @var \DateTime
*/
public $lastUpdate;
/**
* An array of {@link WeatherForecast} objects.
*
* @var array
*
* @see WeatherForecast The WeatherForecast class.
*/
private $forecasts;
/**
* @internal
*/
private $position = 0;
/**
* Create a new Forecast object.
*
* @param $xml
* @param string $units
* @param int $days How many days of forecast to receive.
*
* @internal
*/
public function __construct($xml, $units, $days)
{
$this->city = new City(-1, $xml->location->name, $xml->location->location['longitude'], $xml->location->location['latitude'], $xml->location->country);
$this->sun = new Sun(new \DateTime($xml->sun['rise']), new \DateTime($xml->sun['set']));
$this->lastUpdate = new \DateTime($xml->meta->lastupdate);
$counter = 0;
foreach ($xml->forecast->time as $time) {
$forecast = new Forecast($time, $units);
$forecast->city = $this->city;
$this->forecasts[] = $forecast;
$counter++;
// Make sure to only return the requested number of days.
if ($days <= 5 && $counter == $days * 8) {
break;
} else if ($days > 5 && $counter == $days) {
break;
}
}
}
/**
* @internal
*/
public function rewind()
{
$this->position = 0;
}
/**
* @internal
*/
public function current()
{
return $this->forecasts[$this->position];
}
/**
* @internal
*/
public function key()
{
return $this->position;
}
/**
* @internal
*/
public function next()
{
++$this->position;
}
/**
* @internal
*/
public function valid()
{
return isset($this->forecasts[$this->position]);
}
}

View File

@ -1,118 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap;
/**
* Class WeatherHistory.
*/
class WeatherHistory implements \Iterator
{
/**
* The city object. IMPORTANT: Not all values will be set
*
* @var Util\City
*/
public $city;
/**
* The time needed to calculate the request data.
*
* @var float
*/
public $calctime;
/**
* An array of {@link WeatherHistory} objects.
*
* @var array
*
* @see WeatherForecast The WeatherForecast class.
*/
private $histories;
/**
* @internal
*/
private $position = 0;
public function __construct($weatherHistory, $query)
{
if (isset($weatherHistory['list'][0]['city'])) {
$country = $weatherHistory['list'][0]['city']['country'];
$population = $weatherHistory['list'][0]['city']['population'];
} else {
$country = null;
$population = null;
}
$this->city = new OpenWeatherMap\Util\City($weatherHistory['city_id'], (is_string($query)) ? $query : null, (isset($query['lon'])) ? $query['lon'] : null, (isset($query['lat'])) ? $query['lat'] : null, $country, $population);
$this->calctime = $weatherHistory['calctime'];
foreach ($weatherHistory['list'] as $history) {
if (isset($history['rain'])) {
$units = array_keys($history['rain']);
} else {
$units = array(0 => null);
}
$this->histories[] = new History($this->city, $history['weather'][0], array('now' => $history['main']['temp'], 'min' => $history['main']['temp_min'], 'max' => $history['main']['temp_max']), $history['main']['pressure'], $history['main']['humidity'], $history['clouds']['all'], isset($history['rain']) ? array('val' => $history['rain'][($units[0])], 'unit' => $units[0]) : null, $history['wind'], \DateTime::createFromFormat('U', $history['dt']));
}
}
/**
* @internal
*/
public function rewind()
{
$this->position = 0;
}
/**
* @internal
*/
public function current()
{
return $this->histories[$this->position];
}
/**
* @internal
*/
public function key()
{
return $this->position;
}
/**
* @internal
*/
public function next()
{
++$this->position;
}
/**
* @internal
*/
public function valid()
{
return isset($this->histories[$this->position]);
}
}

View File

@ -1,95 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\AbstractCache;
if (file_exists('../vendor/autoload.php')) {
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
require('../vendor/autoload.php');
} else {
// Library is part of a project.
/** @noinspection PhpIncludeInspection */
require('../../../autoload.php');
}
/**
* Example cache implementation.
*
* @ignore
*/
class ExampleCache extends AbstractCache
{
private function urlToPath($url)
{
$tmp = sys_get_temp_dir();
$dir = $tmp . DIRECTORY_SEPARATOR . "OpenWeatherMapPHPAPI";
if (!is_dir($dir)) {
mkdir($dir);
}
$path = $dir . DIRECTORY_SEPARATOR . md5($url);
return $path;
}
/**
* @inheritdoc
*/
public function isCached($url)
{
$path = $this->urlToPath($url);
if (!file_exists($path) || filectime($path) + $this->seconds < time()) {
echo "Weather data is NOT cached!\n";
return false;
}
echo "Weather data is cached!\n";
return true;
}
/**
* @inheritdoc
*/
public function getCached($url)
{
return file_get_contents($this->urlToPath($url));
}
/**
* @inheritdoc
*/
public function setCached($url, $content)
{
file_put_contents($this->urlToPath($url), $content);
}
}
// Language of data (try your own language here!):
$lang = 'de';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Example 1: Use your own cache implementation. Cache for 10 seconds only in this example.
$owm = new OpenWeatherMap(null, new ExampleCache(), 10);
$weather = $owm->getWeather('Berlin', $units, $lang);
echo "EXAMPLE 1<hr />\n\n\n";
echo $weather->temperature;

View File

@ -1,236 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
if (file_exists('../vendor/autoload.php')) {
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
require('../vendor/autoload.php');
} else {
// Library is part of a project.
/** @noinspection PhpIncludeInspection */
require('../../../autoload.php');
}
// Language of data (try your own language here!):
$lang = 'de';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap();
// Example 1: Get current temperature in Berlin.
$weather = $owm->getWeather('Berlin', $units, $lang);
echo "EXAMPLE 1<hr />\n\n\n";
// $weather contains all available weather information for Berlin.
// Let's get the temperature:
// Returns it as formatted string (using __toString()):
echo $weather->temperature;
echo "<br />\n";
// Returns it as formatted string (using a method):
echo $weather->temperature->getFormatted();
echo "<br />\n";
// Returns the value only:
echo $weather->temperature->getValue();
echo "<br />\n";
// Returns the unit only:
echo $weather->temperature->getUnit();
echo "<br />\n";
/**
* In the example above we're using a "shortcut". OpenWeatherMap returns the minimum temperature of a day,
* the maximum temperature and the temperature right now. If you don't specify which temperature you want, it will default
* to the current temperature. See below how to access the other values. Notice that each of them has implemented the methods
* "getFormatted()", "getValue()", "getUnit()".
*/
// Returns the current temperature:
echo "Current: " . $weather->temperature->now;
echo "<br />\n";
// Returns the minimum temperature:
echo "Minimum: " . $weather->temperature->min;
echo "<br />\n";
// Returns the maximum temperature:
echo "Maximum: " . $weather->temperature->max;
echo "<br />\n";
/**
* When speaking about "current" and "now", this means when the weather data was last updated. You can get this
* via a DateTime object:
*/
echo "Last update: " . $weather->lastUpdate->format('r');
echo "<br />\n";
// Example 2: Get current pressure and humidity in Hongkong.
$weather = $owm->getWeather('Hongkong', $units, $lang);
echo "<br /><br />\n\n\nEXAMPLE 2<hr />\n\n\n";
/**
* You can use the methods above to only get the value or the unit.
*/
echo "Pressure: " . $weather->pressure;
echo "<br />\n";
echo "Humidity: " . $weather->humidity;
echo "<br />\n";
// Example 3: Get today's sunrise and sunset times.
echo "<br /><br />\n\n\nEXAMPLE 3<hr />\n\n\n";
/**
* These functions return a DateTime object.
*/
echo "Sunrise: " . $weather->sun->rise->format('r');
echo "<br />\n";
echo "Sunset: " . $weather->sun->set->format('r');
echo "<br />\n";
// Example 4: Get current temperature from coordinates (Greenland :-) ).
$weather = $owm->getWeather(array('lat' => 77.73038, 'lon' => 41.89604), $units, $lang);
echo "<br /><br />\n\n\nEXAMPLE 4<hr />\n\n\n";
echo "Temperature: " . $weather->temperature;
echo "<br />\n";
// Example 5: Get current temperature from city id. The city is an internal id used by OpenWeatherMap. See example 6 too.
$weather = $owm->getWeather(2172797, $units, $lang);
echo "<br /><br />\n\n\nEXAMPLE 5<hr />\n\n\n";
echo "City: " . $weather->city->name;
echo "<br />\n";
echo "Temperature: " . $weather->temperature;
echo "<br />\n";
// Example 6: Get information about a city.
$weather = $owm->getWeather('Paris', $units, $lang);
echo "<br /><br />\n\n\nEXAMPLE 6<hr />\n\n\n";
echo "Id: " . $weather->city->id;
echo "<br />\n";
echo "Name: " . $weather->city->name;
echo "<br />\n";
echo "Lon: " . $weather->city->lon;
echo "<br />\n";
echo "Lat: " . $weather->city->lat;
echo "<br />\n";
echo "Country: " . $weather->city->country;
echo "<br />\n";
// Example 7: Get wind information.
echo "<br /><br />\n\n\nEXAMPLE 7<hr />\n\n\n";
echo "Speed: " . $weather->wind->speed;
echo "<br />\n";
echo "Direction: " . $weather->wind->direction;
echo "<br />\n";
/**
* For speed and direction there is a description available, which isn't always translated.
*/
echo "Speed: " . $weather->wind->speed->getDescription();
echo "<br />\n";
echo "Direction: " . $weather->wind->direction->getDescription();
echo "<br />\n";
// Example 8: Get information about the clouds.
echo "<br /><br />\n\n\nEXAMPLE 8<hr />\n\n\n";
// The number in braces seems to be an indicator how cloudy the sky is.
echo "Clouds: " . $weather->clouds->getDescription() . " (" . $weather->clouds . ")";
echo "<br />\n";
// Example 9: Get information about precipitation.
echo "<br /><br />\n\n\nEXAMPLE 9<hr />\n\n\n";
echo "Precipation: " . $weather->precipitation->getDescription() . " (" . $weather->precipitation . ")";
echo "<br />\n";
// Example 10: Show copyright notice. WARNING: This is no offical text. This hint was created regarding to http://www.http://openweathermap.org/copyright .
echo "<br /><br />\n\n\nEXAMPLE 10<hr />\n\n\n";
echo $owm::COPYRIGHT;
echo "<br />\n";
// Example 11: Get raw xml data.
echo "<br /><br />\n\n\nEXAMPLE 11<hr />\n\n\n";
echo "<pre><code>" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'xml')) . "</code></pre>";
echo "<br />\n";
// Example 12: Get raw json data.
echo "<br /><br />\n\n\nEXAMPLE 12<hr />\n\n\n";
echo "<code>" . htmlspecialchars($owm->getRawWeatherData('Berlin', $units, $lang, null, 'json')) . "</code>";
echo "<br />\n";
// Example 13: Get raw html data.
echo "<br /><br />\n\n\nEXAMPLE 13<hr />\n\n\n";
echo $owm->getRawWeatherData('Berlin', $units, $lang, null, 'html');
echo "<br />\n";
// Example 14: Error handling.
echo "<br /><br />\n\n\nEXAMPLE 14<hr />\n\n\n";
// Try wrong city name.
try {
$weather = $owm->getWeather("ThisCityNameIsNotValidAndDoesNotExist", $units, $lang);
} catch (OWMException $e) {
echo $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
}
// Try invalid $query.
try {
$weather = $owm->getWeather(new \DateTime('now'), $units, $lang);
} catch (\Exception $e) {
echo $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
}
// Full error handling would look like this:
try {
$weather = $owm->getWeather(-1, $units, $lang);
} catch (OWMException $e) {
echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
} catch (\Exception $e) {
echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
}
// Example 15: Using an api key:
$owm->getWeather('Berlin', $units, $lang, 'Your-Api-Key-Here');

View File

@ -1,69 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
use Cmfcmf\OpenWeatherMap;
if (file_exists('../vendor/autoload.php')) {
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
require('../vendor/autoload.php');
} else {
// Library is part of a project.
/** @noinspection PhpIncludeInspection */
require('../../../autoload.php');
}
// Language of data (try your own language here!):
$lang = 'de';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap();
// Example 1: Get forecast for the next 10 days for Berlin.
$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 10);
echo "EXAMPLE 1<hr />\n\n\n";
echo "City: " . $forecast->city->name;
echo "<br />\n";
echo "LastUpdate: " . $forecast->lastUpdate->format('d.m.Y H:i');
echo "<br />\n";
echo "Sunrise : " . $forecast->sun->rise->format("H:i:s") . " Sunset : " . $forecast->sun->set->format("H:i:s");
echo "<br />\n";
echo "<br />\n";
foreach ($forecast as $weather) {
// Each $weather contains a Cmfcmf\ForecastWeather object which is almost the same as the Cmfcmf\Weather object.
// Take a look into 'Examples_Current.php' to see the available options.
echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i');
echo "<br />\n";
echo $weather->temperature;
echo "<br />\n";
echo "---";
echo "<br />\n";
}
// Example 2: Get forecast for the next 3 days for Berlin.
$forecast = $owm->getWeatherForecast('Berlin', $units, $lang, '', 3);
echo "EXAMPLE 2<hr />\n\n\n";
foreach ($forecast as $weather) {
echo "Weather forecast at " . $weather->time->day->format('d.m.Y') . " from " . $weather->time->from->format('H:i') . " to " . $weather->time->to->format('H:i') . "<br />";
echo $weather->temperature . "<br />\n";
echo "---<br />\n";
}

View File

@ -1,43 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
use Cmfcmf\OpenWeatherMap;
if (file_exists('../vendor/autoload.php')) {
// Library is not part of a project. "composer install" was executed directly on this library's composer file.
require('../vendor/autoload.php');
} else {
// Library is part of a project.
/** @noinspection PhpIncludeInspection */
require('../../../autoload.php');
}
// Language of data (try your own language here!):
$lang = 'en';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap();
// Example 1: Get hourly weather history between 2014-01-01 and today.
$history = $owm->getWeatherHistory('Berlin', new \DateTime('2014-01-01'), new \DateTime('now'), 'hour', $units, $lang);
foreach ($history as $weather) {
echo "Average temperature at " . $weather->time->format('d.m.Y H:i') . ": " . $weather->temperature . "\n\r<br />";
}

View File

@ -1,19 +0,0 @@
Copyright (c) 2013 Christian Flach
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -1,83 +0,0 @@
OpenWeatherMap-PHP-Api
======================
A php api to parse weather data from [OpenWeatherMap.org](http://www.OpenWeatherMap.org). This api tries to normalise and abstract the data and remove inconsistencies.
[![Build Status](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api.png?branch=master)](https://travis-ci.org/cmfcmf/OpenWeatherMap-PHP-Api)[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/quality-score.png?s=f31ca08aa8896416cf162403d34362f0a5da0966)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/)[![Code Coverage](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/badges/coverage.png?s=65153e7cfb13e050d734c645e38f2dd7ea7a6860)](https://scrutinizer-ci.com/g/cmfcmf/OpenWeatherMap-PHP-Api/)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104/big.png)](https://insight.sensiolabs.com/projects/0addfb24-e2b4-4feb-848e-86b2078ca104)
-----------
For example code and how to use this api, please take a look into `Examples_*.php` files and run them in your browser.
- `Examples_Current.php` Shows how to receive the current weather.
- `Examples_Forecast.php` Shows how to receive weather forecasts.
- [*NEW*] `Examples_History.php` Shows how to receive weather history.
- `Examples_Cache.php` Shows how to implement a cache.
**Notice:** This api is not made by OpenWeatherMap, nor their official php api.
Contribute!
===========
I'm very happy if you open **pull requests** or **issues** to help making this API **more awesome**.
Installation
============
This library can be found on [Packagist](https://packagist.org/packages/cmfcmf/openweathermap-php-api).
The recommended way to install this is through [composer](http://getcomposer.org).
Edit your `composer.json` and add:
```json
{
"require": {
"cmfcmf/openweathermap-php-api": "~2.0"
}
}
```
And install dependencies:
```bash
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
```
Example call
============
```php
<?php
use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;
// Must point to composer's autoload file.
require('vendor/autoload.php');
// Language of data (try your own language here!):
$lang = 'de';
// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';
// Get OpenWeatherMap object. Don't use caching (take a look into Example_Cache.php to see how it works).
$owm = new OpenWeatherMap();
try {
$weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
} catch(\Exception $e) {
echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
echo "<br />\n";
}
echo $weather->temperature;
```
License
=======
MIT — Please see the [LICENSE file](https://github.com/Cmfcmf/OpenWeatherMap-PHP-Api/blob/master/LICENSE) distributed with this source code for further information regarding copyright and licensing.
**Please check out the following links to read about the usage policies and the license of OpenWeatherMap before using the service.**
- [OpenWeatherMap.org](http://www.OpenWeatherMap.org)
- [OpenWeatherMap.org/terms](http://www.OpenWeatherMap.org/terms)
- [OpenWeatherMap.org/appid](http://www.OpenWeatherMap.org/appid)

View File

@ -1,30 +0,0 @@
{
"name": "cmfcmf/openweathermap-php-api",
"description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.",
"keywords": ["weather", "OpenWeatherMap", "weather api"],
"homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api",
"license": "MIT",
"authors": [
{
"name": "Christian Flach (cmfcmf)",
"email": "cmfcmf.flach@gmail.com",
"homepage": "http://cmfcmf.github.io",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api/issues",
"source": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git"
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.7.0"
},
"autoload": {
"psr-0": {
"Cmfcmf\\": ""
}
}
}

View File

@ -1,973 +0,0 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "23a2734069dc5af143bb0e0a09160885",
"packages": [],
"packages-dev": [
{
"name": "doctrine/instantiator",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/doctrine/instantiator.git",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
"require": {
"php": ">=5.3,<8.0-DEV"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"ext-pdo": "*",
"ext-phar": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com",
"homepage": "http://ocramius.github.com/"
}
],
"description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
"homepage": "https://github.com/doctrine/instantiator",
"keywords": [
"constructor",
"instantiate"
],
"time": "2015-06-14 21:17:01"
},
{
"name": "phpdocumentor/reflection-docblock",
"version": "2.0.4",
"source": {
"type": "git",
"url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
"reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8",
"reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"suggest": {
"dflydev/markdown": "~1.0",
"erusev/parsedown": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-0": {
"phpDocumentor": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mike van Riel",
"email": "mike.vanriel@naenius.com"
}
],
"time": "2015-02-03 12:10:50"
},
{
"name": "phpspec/prophecy",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/phpspec/prophecy.git",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"reference": "3132b1f44c7bf2ec4c7eb2d3cb78fdeca760d373",
"shasum": ""
},
"require": {
"doctrine/instantiator": "^1.0.2",
"phpdocumentor/reflection-docblock": "~2.0",
"sebastian/comparator": "~1.1"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"psr-0": {
"Prophecy\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Konstantin Kudryashov",
"email": "ever.zet@gmail.com",
"homepage": "http://everzet.com"
},
{
"name": "Marcello Duarte",
"email": "marcello.duarte@gmail.com"
}
],
"description": "Highly opinionated mocking framework for PHP 5.3+",
"homepage": "https://github.com/phpspec/prophecy",
"keywords": [
"Double",
"Dummy",
"fake",
"mock",
"spy",
"stub"
],
"time": "2015-04-27 22:15:08"
},
{
"name": "phpunit/php-code-coverage",
"version": "2.1.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/631e365cf26bb2c078683e8d9bcf8bc631ac4d44",
"reference": "631e365cf26bb2c078683e8d9bcf8bc631ac4d44",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"phpunit/php-file-iterator": "~1.3",
"phpunit/php-text-template": "~1.2",
"phpunit/php-token-stream": "~1.3",
"sebastian/environment": "~1.0",
"sebastian/version": "~1.0"
},
"require-dev": {
"ext-xdebug": ">=2.1.4",
"phpunit/phpunit": "~4"
},
"suggest": {
"ext-dom": "*",
"ext-xdebug": ">=2.2.1",
"ext-xmlwriter": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
"homepage": "https://github.com/sebastianbergmann/php-code-coverage",
"keywords": [
"coverage",
"testing",
"xunit"
],
"time": "2015-06-19 07:11:55"
},
{
"name": "phpunit/php-file-iterator",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb",
"reference": "a923bb15680d0089e2316f7a4af8f437046e96bb",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
"homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
"keywords": [
"filesystem",
"iterator"
],
"time": "2015-04-02 05:19:05"
},
{
"name": "phpunit/php-text-template",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"Text/"
]
},
"notification-url": "https://packagist.org/downloads/",
"include-path": [
""
],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Simple template engine.",
"homepage": "https://github.com/sebastianbergmann/php-text-template/",
"keywords": [
"template"
],
"time": "2014-01-30 17:20:04"
},
{
"name": "phpunit/php-timer",
"version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
"reference": "83fe1bdc5d47658b727595c14da140da92b3d66d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d",
"reference": "83fe1bdc5d47658b727595c14da140da92b3d66d",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Utility class for timing",
"homepage": "https://github.com/sebastianbergmann/php-timer/",
"keywords": [
"timer"
],
"time": "2015-06-13 07:35:30"
},
{
"name": "phpunit/php-token-stream",
"version": "1.4.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
"reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9",
"reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Wrapper around PHP's tokenizer extension.",
"homepage": "https://github.com/sebastianbergmann/php-token-stream/",
"keywords": [
"tokenizer"
],
"time": "2015-06-19 03:43:16"
},
{
"name": "phpunit/phpunit",
"version": "4.7.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "e5f851f324f7add846316f39e668e9deac97a103"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e5f851f324f7add846316f39e668e9deac97a103",
"reference": "e5f851f324f7add846316f39e668e9deac97a103",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-json": "*",
"ext-pcre": "*",
"ext-reflection": "*",
"ext-spl": "*",
"php": ">=5.3.3",
"phpspec/prophecy": "~1.3,>=1.3.1",
"phpunit/php-code-coverage": "~2.1",
"phpunit/php-file-iterator": "~1.4",
"phpunit/php-text-template": "~1.2",
"phpunit/php-timer": ">=1.0.6",
"phpunit/phpunit-mock-objects": "~2.3",
"sebastian/comparator": "~1.1",
"sebastian/diff": "~1.2",
"sebastian/environment": "~1.2",
"sebastian/exporter": "~1.2",
"sebastian/global-state": "~1.0",
"sebastian/version": "~1.0",
"symfony/yaml": "~2.1|~3.0"
},
"suggest": {
"phpunit/php-invoker": "~1.1"
},
"bin": [
"phpunit"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.7.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "The PHP Unit Testing framework.",
"homepage": "https://phpunit.de/",
"keywords": [
"phpunit",
"testing",
"xunit"
],
"time": "2015-06-18 13:33:26"
},
{
"name": "phpunit/phpunit-mock-objects",
"version": "2.3.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
"reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/92408bb1968a81b3217a6fdf6c1a198da83caa35",
"reference": "92408bb1968a81b3217a6fdf6c1a198da83caa35",
"shasum": ""
},
"require": {
"doctrine/instantiator": "~1.0,>=1.0.2",
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"suggest": {
"ext-soap": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.3.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sb@sebastian-bergmann.de",
"role": "lead"
}
],
"description": "Mock Object library for PHPUnit",
"homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
"keywords": [
"mock",
"xunit"
],
"time": "2015-06-11 15:55:48"
},
{
"name": "sebastian/comparator",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
"reference": "1dd8869519a225f7f2b9eb663e225298fade819e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e",
"reference": "1dd8869519a225f7f2b9eb663e225298fade819e",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/diff": "~1.2",
"sebastian/exporter": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Provides the functionality to compare PHP values for equality",
"homepage": "http://www.github.com/sebastianbergmann/comparator",
"keywords": [
"comparator",
"compare",
"equality"
],
"time": "2015-01-29 16:28:08"
},
{
"name": "sebastian/diff",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/diff.git",
"reference": "863df9687835c62aa423a22412d26fa2ebde3fd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3",
"reference": "863df9687835c62aa423a22412d26fa2ebde3fd3",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kore Nordmann",
"email": "mail@kore-nordmann.de"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Diff implementation",
"homepage": "http://www.github.com/sebastianbergmann/diff",
"keywords": [
"diff"
],
"time": "2015-02-22 15:13:53"
},
{
"name": "sebastian/environment",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
"reference": "5a8c7d31914337b69923db26c4221b81ff5a196e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e",
"reference": "5a8c7d31914337b69923db26c4221b81ff5a196e",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Provides functionality to handle HHVM/PHP environments",
"homepage": "http://www.github.com/sebastianbergmann/environment",
"keywords": [
"Xdebug",
"environment",
"hhvm"
],
"time": "2015-01-01 10:01:08"
},
{
"name": "sebastian/exporter",
"version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
"reference": "84839970d05254c73cde183a721c7af13aede943"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943",
"reference": "84839970d05254c73cde183a721c7af13aede943",
"shasum": ""
},
"require": {
"php": ">=5.3.3",
"sebastian/recursion-context": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Volker Dusch",
"email": "github@wallbash.com"
},
{
"name": "Bernhard Schussek",
"email": "bschussek@2bepublished.at"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides the functionality to export PHP variables for visualization",
"homepage": "http://www.github.com/sebastianbergmann/exporter",
"keywords": [
"export",
"exporter"
],
"time": "2015-01-27 07:23:06"
},
{
"name": "sebastian/global-state",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/global-state.git",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
},
"suggest": {
"ext-uopz": "*"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
}
],
"description": "Snapshotting of global state",
"homepage": "http://www.github.com/sebastianbergmann/global-state",
"keywords": [
"global state"
],
"time": "2014-10-06 09:23:50"
},
{
"name": "sebastian/recursion-context",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
"reference": "3989662bbb30a29d20d9faa04a846af79b276252"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252",
"reference": "3989662bbb30a29d20d9faa04a846af79b276252",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Jeff Welch",
"email": "whatthejeff@gmail.com"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de"
},
{
"name": "Adam Harvey",
"email": "aharvey@php.net"
}
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
"time": "2015-01-24 09:48:32"
},
{
"name": "sebastian/version",
"version": "1.0.5",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
"reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
"reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
"shasum": ""
},
"type": "library",
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "lead"
}
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
"time": "2015-02-24 06:35:25"
},
{
"name": "symfony/yaml",
"version": "v2.7.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
"reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Yaml/zipball/9808e75c609a14f6db02f70fccf4ca4aab53c160",
"reference": "9808e75c609a14f6db02f70fccf4ca4aab53c160",
"shasum": ""
},
"require": {
"php": ">=5.3.9"
},
"require-dev": {
"symfony/phpunit-bridge": "~2.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.7-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Yaml\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2015-06-10 15:30:22"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {
"php": ">=5.3.0"
},
"platform-dev": []
}

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--suppress XmlUnboundNsPrefix -->
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="cmfcmf/openweathermap-php-api test suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory suffix="Test.php">./</directory>
<directory suffix="Interface.php">./</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>

View File

@ -1,53 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Fetcher;
use \Cmfcmf\OpenWeatherMap\Fetcher\CurlFetcher;
/**
* @requires function curl_version
*/
class CurlFetcherTest extends \PHPUnit_Framework_TestCase
{
public function testInvalidUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('http://notexisting.example.com');
$this->assertSame(false, $content);
}
public function testEmptyUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('');
$this->assertSame(false, $content);
}
public function testValidUrl()
{
$fetcher = new CurlFetcher();
$content = $fetcher->fetch('http://httpbin.org/html');
$this->assertContains('Herman Melville', $content);
}
}

View File

@ -1,59 +0,0 @@
<?php
/**
* OpenWeatherMap-PHP-API A php api to parse weather data from http://www.OpenWeatherMap.org .
*
* @license MIT
*
* Please see the LICENSE file distributed with this source code for further
* information regarding copyright and licensing.
*
* Please visit the following links to read about the usage policies and the license of
* OpenWeatherMap before using this class:
*
* @see http://www.OpenWeatherMap.org
* @see http://www.OpenWeatherMap.org/terms
* @see http://openweathermap.org/appid
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Fetcher;
use \Cmfcmf\OpenWeatherMap\Fetcher\FileGetContentsFetcher;
class FileGetContentsFetcherTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!ini_get('allow_url_fopen')) {
$this->markTestSkipped('"allow_url_fopen" is set to off.');
}
}
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testInvalidUrl()
{
$fetcher = new FileGetContentsFetcher();
$fetcher->fetch('http://notexisting.example.com');
}
/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testEmptyUrl()
{
$fetcher = new FileGetContentsFetcher();
$fetcher->fetch('');
}
public function testValidUrl()
{
$fetcher = new FileGetContentsFetcher();
$content = $fetcher->fetch('http://httpbin.org/html');
$this->assertContains('Herman Melville', $content);
}
}

View File

@ -1,62 +0,0 @@
<?php
/**
* Copyright Zikula Foundation 2014 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPv3 (or at your option any later version).
* @package OpenWeatherMap-PHP-Api
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
use Cmfcmf\OpenWeatherMap\Util\Sun;
class SunTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Sun
*/
private $sun;
public function testSunRise()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 20:00:00');
$this->givenThereIsASunObject($rise, $set);
$this->assertSame($rise, $this->sun->rise);
}
public function testSunSet()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 20:00:00');
$this->givenThereIsASunObject($rise, $set);
$this->assertSame($set, $this->sun->set);
}
private function givenThereIsASunObject($rise, $set)
{
$this->sun = new Sun($rise, $set);
}
/**
* @expectedException \LogicException
*/
public function testSunSetBeforeSunRiseException()
{
$rise = new \DateTime('2014-01-01 08:00:00');
$set = new \DateTime('2014-01-01 7:00:00');
$this->givenThereIsASunObject($rise, $set);
}
}

View File

@ -1,159 +0,0 @@
<?php
/**
* Copyright Zikula Foundation 2014 - Zikula Application Framework
*
* This work is contributed to the Zikula Foundation under one or more
* Contributor Agreements and licensed to You under the following license:
*
* @license GNU/LGPv3 (or at your option any later version).
* @package OpenWeatherMap-PHP-Api
*
* Please see the NOTICE file distributed with this source code for further
* information regarding copyright and licensing.
*/
namespace Cmfcmf\OpenWeatherMap\Tests\Util;
use \Cmfcmf\OpenWeatherMap\Util\Unit;
class UnitTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Unit
*/
private $unit;
const POSITIVE_INT_VALUE = 23;
const POSITIVE_FLOAT_VALUE = 48.23534;
const NEGATIVE_INT_VALUE = -30;
const NEGATIVE_FLOAT_VALUE = -93.45839;
const ZERO_INT_VALUE = 0;
const ZERO_FLOAT_VALUE = 0.0;
public function testGetValueWithPositiveIntValue()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
$this->assertSame((float)self::POSITIVE_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithPositiveFloatValue()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_FLOAT_VALUE);
$this->assertSame(self::POSITIVE_FLOAT_VALUE, $this->unit->getValue());
}
public function testGetValueWithNegativeIntValue()
{
$this->givenThereIsAUnitWithValue(self::NEGATIVE_INT_VALUE);
$this->assertSame((float)self::NEGATIVE_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithNegativeFloatValue()
{
$this->givenThereIsAUnitWithValue(self::NEGATIVE_FLOAT_VALUE);
$this->assertSame(self::NEGATIVE_FLOAT_VALUE, $this->unit->getValue());
}
public function testGetValueWithZeroIntValue()
{
$this->givenThereIsAUnitWithValue(self::ZERO_INT_VALUE);
$this->assertSame((float)self::ZERO_INT_VALUE, $this->unit->getValue());
}
public function testGetValueWithZeroFloatValue()
{
$this->givenThereIsAUnitWithValue(self::ZERO_FLOAT_VALUE);
$this->assertSame(self::ZERO_FLOAT_VALUE, $this->unit->getValue());
}
private function givenThereIsAUnitWithValue($value, $unit = null)
{
$this->unit = $unit === null ? new Unit($value) : new Unit($value, $unit);
}
public function testGetUnitWithEmptyUnit()
{
$this->givenThereIsAUnitWithUnit("");
$this->assertSame("", $this->unit->getUnit());
}
public function testGetUnitWithStringAsUnit()
{
$this->givenThereIsAUnitWithUnit("Hey! I'm cmfcmf");
$this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit());
}
public function testCelsiusFixture()
{
$this->givenThereIsAUnitWithUnit("celsius");
$this->assertSame("&deg;C", $this->unit->getUnit());
}
public function testFahrenheitFixture()
{
$this->givenThereIsAUnitWithUnit("fahrenheit");
$this->assertSame("F", $this->unit->getUnit());
}
private function givenThereIsAUnitWithUnit($unit)
{
$this->unit = new Unit(0, $unit);
}
public function testGetDescriptionWithEmptyDescription()
{
$this->givenThereIsAUnitWithDescription("");
$this->assertSame("", $this->unit->getDescription());
}
public function testGetDescriptionWithStringAsDescription()
{
$this->givenThereIsAUnitWithDescription("Hey! I'm cmfcmf");
$this->assertSame("Hey! I'm cmfcmf", $this->unit->getDescription());
}
private function givenThereIsAUnitWithDescription($description)
{
$this->unit = new Unit(0, "", $description);
}
public function testGetFormattedWithoutUnit()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE);
$this->assertEquals(self::POSITIVE_INT_VALUE, $this->unit->getFormatted());
$this->assertEquals($this->unit->getValue(), $this->unit->getFormatted());
}
public function testGetFormattedWithUnit()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
$this->assertEquals(self::POSITIVE_INT_VALUE . ' K', $this->unit->getFormatted());
$this->assertEquals($this->unit->getValue() . ' ' . $this->unit->getUnit(), $this->unit->getFormatted());
}
public function testToString()
{
$this->givenThereIsAUnitWithValue(self::POSITIVE_INT_VALUE, 'K');
$this->assertEquals($this->unit->getFormatted(), $this->unit);
}
}

View File

@ -1,12 +0,0 @@
<?php
call_user_func(function () {
if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) {
throw new \RuntimeException('Did not find vendor/autoload.php. Did you run "composer install --dev"?');
}
/** @noinspection PhpIncludeInspection */
require_once $autoloadFile;
ini_set('date.timezone', 'Europe/Berlin');
});

View File

@ -1,413 +0,0 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0 class loader
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (is_file($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}

View File

@ -1,9 +0,0 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -1,10 +0,0 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Cmfcmf\\' => array($vendorDir . '/cmfcmf/openweathermap-php-api'),
);

View File

@ -1,9 +0,0 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@ -1,50 +0,0 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6bf0e42f34a65c53928f3dc22e5b93d3
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6bf0e42f34a65c53928f3dc22e5b93d3', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit6bf0e42f34a65c53928f3dc22e5b93d3', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
function composerRequire6bf0e42f34a65c53928f3dc22e5b93d3($file)
{
require $file;
}

View File

@ -1,51 +0,0 @@
[
{
"name": "cmfcmf/openweathermap-php-api",
"version": "v2.0.7",
"version_normalized": "2.0.7.0",
"source": {
"type": "git",
"url": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api.git",
"reference": "ab387ebcad332b1e58be443f760e1235e7976443"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/cmfcmf/OpenWeatherMap-PHP-Api/zipball/ab387ebcad332b1e58be443f760e1235e7976443",
"reference": "ab387ebcad332b1e58be443f760e1235e7976443",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.7.0"
},
"time": "2015-06-23 21:07:37",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Cmfcmf\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Christian Flach (cmfcmf)",
"email": "cmfcmf.flach@gmail.com",
"homepage": "http://cmfcmf.github.io",
"role": "Developer"
}
],
"description": "A php api to parse weather data from OpenWeatherMap.org. This api tries to normalise and abstract the data and remove inconsistencies.",
"homepage": "https://github.com/cmfcmf/OpenWeatherMap-PHP-Api",
"keywords": [
"OpenWeatherMap",
"weather",
"weather api"
]
}
]