Nominatim/lib/website.php
Sarah Hoffmann d45524cbfb introduce accessor function for URL parameter
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.
2016-06-11 23:07:06 +02:00

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];
}