本文整理汇总了PHP中Filesystem::getExternUrlContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::getExternUrlContent方法的具体用法?PHP Filesystem::getExternUrlContent怎么用?PHP Filesystem::getExternUrlContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::getExternUrlContent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fetchElevationFor
/**
* Fetch elevation
* @param array $latitudes
* @param array $longitudes
* @return array
* @throws \RuntimeException
*/
protected function fetchElevationFor(array $latitudes, array $longitudes)
{
$latitudeString = implode(',', $latitudes);
$longitudeString = implode(',', $longitudes);
$url = 'http://api.geonames.org/srtm3JSON?lats=' . $latitudeString . '&lngs=' . $longitudeString . '&username=' . $this->USERNAME;
$response = json_decode(\Filesystem::getExternUrlContent($url), true);
if (is_null($response) || !isset($response['geonames']) || !is_array($response['geonames'])) {
throw new \RuntimeException('Geonames returned malformed code.');
}
$elevationData = array();
$responseLength = count($response['geonames']);
for ($i = 0; $i < $responseLength; $i++) {
$elevationData[] = (int) $response['geonames'][$i]['srtm3'];
}
return $elevationData;
}
示例2: fetchElevationFor
/**
* Fetch elevation
* @param array $latitudes
* @param array $longitudes
* @return array
*/
protected function fetchElevationFor(array $latitudes, array $longitudes)
{
$numberOfCoordinates = count($latitudes);
$coordinatesString = '';
for ($i = 0; $i < $numberOfCoordinates; $i++) {
$coordinatesString .= $latitudes[$i] . ',' . $longitudes[$i] . '|';
}
$url = 'http://maps.googleapis.com/maps/api/elevation/json?locations=' . substr($coordinatesString, 0, -1) . '&sensor=false';
$response = json_decode(\Filesystem::getExternUrlContent($url), true);
if (is_null($response) || !is_array($response) || !isset($response['results']) || !isset($response['results'][0]['elevation'])) {
throw new \RuntimeException('GoogleMaps returned malformed code.');
}
$elevationData = array();
$responseLength = count($response['results']);
for ($i = 0; $i < $responseLength; $i++) {
$elevationData[] = (int) $response['results'][$i]['elevation'];
}
return $elevationData;
}
示例3: fetchElevationFor
/**
* Fetch elevation
* @param array $latitudes
* @param array $longitudes
* @return array
* @throws \RuntimeException
*/
protected function fetchElevationFor(array $latitudes, array $longitudes)
{
$numberOfCoordinates = count($latitudes);
$coordinatesArray = array();
for ($i = 0; $i < $numberOfCoordinates; $i++) {
$coordinatesArray[] = array($latitudes[$i], $longitudes[$i]);
}
$coordinatesString = json_encode($coordinatesArray);
$url = 'http://www.datasciencetoolkit.org/coordinates2statistics/' . $coordinatesString . '?statistics=elevation';
$response = json_decode(\Filesystem::getExternUrlContent($url), true);
if (is_null($response) || !is_array($response) || !isset($response[0]['statistics']) || !isset($response[0]['statistics']['elevation'])) {
throw new \RuntimeException('DataScienceToolkit returned malformed code.');
}
$elevationData = array();
$responseLength = count($response);
for ($i = 0; $i < $responseLength; $i++) {
$elevationData[] = (int) $response[$i]['statistics']['elevation']['value'];
}
return $elevationData;
}
示例4: setFromURL
/**
* Set from url
* @param string $url
* @param string $cacheKey [optional] if true result will be cached
*/
public function setFromURL($url, $cacheKey = false)
{
if ($cacheKey !== false) {
$this->Result = Cache::get($cacheKey, 1);
if ($this->Result != null) {
return;
} else {
$this->Result = array();
}
}
if (defined('OPENWEATHERMAP_API_KEY') && strlen(OPENWEATHERMAP_API_KEY)) {
$url .= '&APPID=' . OPENWEATHERMAP_API_KEY;
}
$this->setFromJSON(\Filesystem::getExternUrlContent($url));
if ($cacheKey !== false) {
Cache::set($cacheKey, $this->Result, 7200, 1);
}
}