1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* OpenWeatherMap-PHP-API — A php api to parse weather data from http://www.OpenWeatherMap.org . |
4
|
|
|
* |
5
|
|
|
* @license MIT |
6
|
|
|
* |
7
|
|
|
* Please see the LICENSE file distributed with this source code for further |
8
|
|
|
* information regarding copyright and licensing. |
9
|
|
|
* |
10
|
|
|
* Please visit the following links to read about the usage policies and the license of |
11
|
|
|
* OpenWeatherMap before using this class: |
12
|
|
|
* |
13
|
|
|
* @see http://www.OpenWeatherMap.org |
14
|
|
|
* @see http://www.OpenWeatherMap.org/terms |
15
|
|
|
* @see http://openweathermap.org/appid |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Cmfcmf\OpenWeatherMap\Tests; |
19
|
|
|
|
20
|
|
|
use Cmfcmf\OpenWeatherMap\Fetcher\FetcherInterface; |
21
|
|
|
|
22
|
|
|
class TestFetcher implements FetcherInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Fetch contents from the specified url. |
26
|
|
|
* |
27
|
|
|
* @param string $url The url to be fetched. |
28
|
|
|
* |
29
|
|
|
* @return string The fetched content. |
30
|
|
|
* |
31
|
|
|
* @api |
32
|
|
|
*/ |
33
|
|
|
public function fetch($url) |
34
|
|
|
{ |
35
|
|
|
$format = strpos($url, 'json') !== false ? 'json' : 'xml'; |
36
|
|
|
if (strpos($url, 'forecast') !== false) { |
37
|
|
|
return $this->forecast($format); |
38
|
|
|
} else if (strpos($url, 'group') !== false) { |
39
|
|
|
return $this->group($format); |
40
|
|
|
} else { |
41
|
|
|
return $this->currentWeather($format); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function currentWeather($format) |
46
|
|
|
{ |
47
|
|
|
if ($format == 'xml') { |
48
|
|
|
return FakeData::CURRENT_WEATHER_XML; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function forecast($format) |
53
|
|
|
{ |
54
|
|
|
if ($format == 'xml') { |
55
|
|
|
return FakeData::forecastXML(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function group($format) |
60
|
|
|
{ |
61
|
|
|
if ($format == 'json') { |
62
|
|
|
return FakeData::WEATHER_GROUP_JSON; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|