juggl/public/api/services/paramCleaner.inc.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2021-01-03 12:29:41 +01:00
<?php
class ParamCleaner {
function __construct (array $params) {
$this->sourceParams = $params;
$this->selectedParams = $params;
$this->errorCount = 0;
$this->errorMessage = "";
}
function select (string $prop = "") {
if ($prop == "") {
$this->selectedParams = $this->sourceParams;
} else {
$this->selectedParams = $this->selectedParams[$prop];
}
}
function get (string $prop) {
if(isset($this->selectedParams[$prop])) {
return $this->selectedParams[$prop];
} else {
$this->errorCount += 1;
$this->errorMessage .= "Property \"{$prop}\" missing. ";
return null;
}
}
function exists (array $props) {
foreach ($props as $prop) {
if(isset($this->selectedParams[$prop]) == false) {
return false;
}
}
return true;
}
function hasErrorOccurred () {
return $this->errorCount > 0;
}
function getErrorMessage () {
return $this->errorMessage;
}
function resetErrors () {
$this->errorMessage = "";
$this->errorCount = 0;
}
}
?>