Source
// Having only a root folder is the same as being empty. Temporary modify data to check if it is actually empty.
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* API validator
*/
class CApiInputValidator {
/**
* Base validation function.
*
* @param array $rule validation rule
* @param mixed $data import data
* @param string $path data path (for error reporting)
* @param string $error
*
* @return bool
*/
public static function validate(array $rule, &$data, $path, &$error) {
$error = '';
return self::validateData($rule, $data, $path, $error)
&& self::validateDataUniqueness($rule, $data, $path, $error);
}
/**
* Base uniqueness validation function.
*
* @param array $rule validation rule
* @param mixed $data import data
* @param string $path data path (for error reporting)
* @param string $error
*
* @return bool
*/
public static function validateUniqueness(array $rule, $data, $path, &$error) {
$error = '';
return self::validateDataUniqueness($rule, $data, $path, $error);
}
/**
* Base data validation function.
*
* @param array $rule
* @param mixed $data
* @param string $path
* @param string $error
*
* @return bool
*/
private static function validateData($rule, &$data, $path, &$error) {
switch ($rule['type']) {
case API_CALC_FORMULA:
return self::validateCalcFormula($rule, $data, $path, $error);
case API_COLOR:
return self::validateColor($rule, $data, $path, $error);
case API_COND_FORMULA:
return self::validateCondFormula($rule, $data, $path, $error);
case API_COND_FORMULAID:
return self::validateCondFormulaId($rule, $data, $path, $error);
case API_STRING_UTF8:
return self::validateStringUtf8($rule, $data, $path, $error);
case API_STRINGS_UTF8:
return self::validateStringsUtf8($rule, $data, $path, $error);
case API_INT32:
return self::validateInt32($rule, $data, $path, $error);