50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
|
<?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;
|
||
|
}
|
||
|
}
|
||
|
?>
|