additional checks if a parameter is set; function to create paths added
This commit is contained in:
parent
075f05aaf9
commit
eb2e78a125
2 changed files with 24 additions and 3 deletions
|
@ -48,4 +48,19 @@ function endsWith($haystack, $needle) {
|
|||
|
||||
return $length === 0 || (substr($haystack, -$length) === $needle);
|
||||
}
|
||||
|
||||
function generatePath($parts, $basePath = __DIR__) {
|
||||
$path = $basePath;
|
||||
if (!is_array($parts)) {
|
||||
$parts = [$parts];
|
||||
}
|
||||
foreach ($parts as $part) {
|
||||
$path .= DIRECTORY_SEPARATOR.generatePathName($part);
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
function generatePathName($name) {
|
||||
return urlencode($name);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -103,7 +103,13 @@ function getMandatoryFileParameter($parameterName, $message = '', $json = false)
|
|||
}
|
||||
|
||||
function getPostParameter($parameterName) {
|
||||
return $_POST[$parameterName];
|
||||
if (array_key_exists($parameterName, $_POST)
|
||||
&& isset($_POST[$parameterName])
|
||||
&& !empty($_POST[$parameterName])) {
|
||||
return $_POST[$parameterName];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function getOptionalPostParameter($parameterName, $default = NULL) {
|
||||
|
@ -123,7 +129,7 @@ function getGetParameter($parameterName) {
|
|||
}
|
||||
|
||||
function getOptionalGetParameter($parameterName, $default = NULL) {
|
||||
$parameter = getPostParameter($parameterName);
|
||||
$parameter = getGetParameter($parameterName);
|
||||
|
||||
return handleOptionalParameter($parameter, $default);
|
||||
}
|
||||
|
@ -143,7 +149,7 @@ function handleOptionalParameter($parameter, $default) {
|
|||
|
||||
function handleMandatoryParameter($parameterName, $parameter, $message, $json) {
|
||||
if (!isset($parameter) || is_null($parameter) || empty($parameter)) {
|
||||
if (empty($message)) {
|
||||
if (empty($message) || is_null($message)) {
|
||||
if ($json) {
|
||||
$message = ['msg' => 'Missing parameter.', 'parameters' => ['missing_parameter' => $parameterName]];
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue