mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-11-24 14:32:29 +03:00
d45524cbfb
These functions take care of type conversion and check that the parameters contain legal values. The API now returns a Bad Request error if the format is wrong.
58 lines
1.2 KiB
PHP
58 lines
1.2 KiB
PHP
<?php
|
|
|
|
/***************************************************************************
|
|
*
|
|
* Functions for parsing URL parameters
|
|
*
|
|
*/
|
|
|
|
function getParamBool($sName, $bDefault=false)
|
|
{
|
|
if (!isset($_GET[$sName])) return $bDefault;
|
|
|
|
return (bool) $_GET[$sName];
|
|
}
|
|
|
|
function getParamInt($sName, $bDefault=false)
|
|
{
|
|
if (!isset($_GET[$sName])) return $bDefault;
|
|
|
|
if (!preg_match('/^[+-][0-9]+$/', $_GET[$sName]))
|
|
{
|
|
userError("Integer number expected for parameter '$sName'");
|
|
}
|
|
|
|
return (int) $_GET[$sName];
|
|
}
|
|
|
|
function getParamFloat($sName, $bDefault=false)
|
|
{
|
|
if (!isset($_GET[$sName])) return $bDefault;
|
|
|
|
if (!preg_match('/^[+-]?[0-9]*\.?[0-9]+$/', $_GET[$sName]))
|
|
{
|
|
userError("Floating-point number expected for parameter '$sName'");
|
|
}
|
|
|
|
return (float) $_GET[$sName];
|
|
}
|
|
|
|
function getParamString($sName, $bDefault=false)
|
|
{
|
|
if (!isset($_GET[$sName])) return $bDefault;
|
|
|
|
return $_GET[$sName];
|
|
}
|
|
|
|
function getParamSet($sName, $aValues, $sDefault=false)
|
|
{
|
|
if (!isset($_GET[$sName])) return $sDefault;
|
|
|
|
if (!in_array($_GET[$sName], $aValues))
|
|
{
|
|
userError("Parameter '$sName' must be one of: ".join(', ', $aValues));
|
|
}
|
|
|
|
return $_GET[$sName];
|
|
}
|