finish #102
This commit is contained in:
@@ -23,7 +23,12 @@ class SpsApi extends Api {
|
||||
* Route string for the domain paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterDomain = "/domain/:domain";
|
||||
public static $routeParameterDomain = "(/domain/:domain)";
|
||||
/**
|
||||
* Route string for the range paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterRange = "(/range/:range)";
|
||||
|
||||
/**
|
||||
* Route string for the Longitude paramter
|
||||
@@ -67,6 +72,12 @@ class SpsApi extends Api {
|
||||
*/
|
||||
public static $keyLat = "latitude";
|
||||
|
||||
/**
|
||||
* Keyword for range arguments
|
||||
* @var string
|
||||
*/
|
||||
public static $keyRange = "range";
|
||||
|
||||
/*
|
||||
* Varible for the range of the searchpolygon
|
||||
* @var float
|
||||
@@ -141,8 +152,8 @@ class SpsApi extends Api {
|
||||
* @return querry result as xml
|
||||
*/
|
||||
public function sendSpsCoordinateQuery($queryArgs) {
|
||||
|
||||
// check arguments of the query
|
||||
|
||||
// check arguments of the query
|
||||
if (!array_key_exists(self::$keyLong, $queryArgs) || !array_key_exists(self::$keyLat, $queryArgs)) {
|
||||
return null;
|
||||
}
|
||||
@@ -154,6 +165,14 @@ class SpsApi extends Api {
|
||||
}
|
||||
|
||||
// build a request polygon
|
||||
if (array_key_exists(self::$keyRange, $queryArgs)) {
|
||||
$newRange = $queryArgs[self::$keyRange];
|
||||
if ($this->validRange($newRange)) {
|
||||
self::$range = $newRange;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$queryArgs[self::$keyPoly] = $this->createPolygon($latitude, $longitude, self::$range);
|
||||
|
||||
// send querry
|
||||
@@ -161,6 +180,19 @@ class SpsApi extends Api {
|
||||
return $this->serialManager->arrayToSps($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if a string is a valid Longitude
|
||||
* @param string $string
|
||||
* @return bool
|
||||
*/
|
||||
private function validRange($string) {
|
||||
$digit = str_replace(".", "", $string);
|
||||
if (ctype_digit($digit)) {
|
||||
return TRUE;
|
||||
};
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if a string is a valid Longitude
|
||||
* @param string $string
|
||||
|
||||
@@ -122,7 +122,7 @@ class SpsSqlManager extends SQLManager {
|
||||
// build query string
|
||||
$query = self::$selectTerm;
|
||||
if ($this->validAliasString($alias)) {
|
||||
$query .= self::$aliasTerm . self::$quoteTerm . $alias . self::$quoteTerm . self::$addDomainTerm($domain);
|
||||
$query .= self::$aliasTerm . self::$quoteTerm . $alias . self::$quoteTerm . $this->addDomainTerm($domain);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -10,31 +10,25 @@ $headers = apache_request_headers();
|
||||
$app = new \api\SpsApi($headers);
|
||||
|
||||
// HTTP-Get-Methods
|
||||
$app->get(\api\SpsApi::$routeParameterAlias, function ($alias) use ($app) {
|
||||
$app->get(\api\SpsApi::$routeParameterAlias . \api\SpsApi::$routeParameterDomain, function ($alias, $domain = -1) use ($app) {
|
||||
$args = array();
|
||||
$args[\api\SpsApi::$keyAlias] = $alias;
|
||||
if ($domain != -1) {
|
||||
$args[\api\SpsApi::$keyDomain] = $domain;
|
||||
}
|
||||
echo $app->sendSpsAliasQuery($args);
|
||||
});
|
||||
|
||||
$app->get(\api\SpsApi::$routeParameterAlias . \api\SpsApi::$routeParameterDomain, function ($alias, $domain) use ($app) {
|
||||
$args = array();
|
||||
$args[\api\SpsApi::$keyAlias] = $alias;
|
||||
$args[\api\SpsApi::$keyDomain] = $domain;
|
||||
echo $app->sendSpsAliasQuery($args);
|
||||
});
|
||||
|
||||
$app->get(\api\SpsApi::$routeParameterLatitude . \api\SpsApi::$routeParameterLongitude, function ($latitude, $longitude) use ($app) {
|
||||
$app->get(\api\SpsApi::$routeParameterLatitude . \api\SpsApi::$routeParameterLongitude . \api\SpsApi::$routeParameterDomain . \api\SpsApi ::$routeParameterRange, function ($latitude, $longitude, $domain = -1, $range = -1) use ($app) {
|
||||
$args = array();
|
||||
$args[\api\SpsApi::$keyLong] = $longitude;
|
||||
$args[\api\SpsApi::$keyLat] = $latitude;
|
||||
echo ($app->sendSpsCoordinateQuery($args));
|
||||
});
|
||||
|
||||
$app->get(\api\SpsApi::$routeParameterLatitude . \api\SpsApi::$routeParameterLongitude . \api\SpsApi::$routeParameterDomain, function ($latitude, $longitude, $domain) use ($app) {
|
||||
$args = array();
|
||||
$args[\api\SpsApi::$keyLong] = $longitude;
|
||||
$args[\api\SpsApi::$keyLat] = $latitude;
|
||||
$args[\api\SpsApi::$keyDomain] = $domain;
|
||||
if ($domain != -1) {
|
||||
$args[\api\SpsApi::$keyDomain] = $domain;
|
||||
}
|
||||
if ($range != -1) {
|
||||
$args[\api\SpsApi::$keyRange] = $range;
|
||||
}
|
||||
echo ($app->sendSpsCoordinateQuery($args));
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user