Source
xxxxxxxxxx
<?php declare(strict_types = 0);
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
abstract class CControllerSlaCreateUpdate extends CController {
/**
* @param array $schedule_enabled
* @param array $schedule_periods
*
* @return array
*/
protected static function validateCustomSchedule(array $schedule_enabled, array $schedule_periods): array {
$schedule = [];
$incorrect_schedule_exception = new InvalidArgumentException(
_s('Incorrect schedule: %1$s.',
_('comma separated list of time periods is expected for scheduled week days')
)
);
foreach (range(0, 6) as $weekday) {
if (!array_key_exists($weekday, $schedule_enabled)) {
continue;
}
if (!array_key_exists($weekday, $schedule_periods)) {
throw new InvalidArgumentException(_('Unexpected server error.'));
}
if (!is_string($schedule_periods[$weekday])) {
throw new InvalidArgumentException(_('Unexpected server error.'));
}
$weekday_schedule_periods = trim($schedule_periods[$weekday]);
if ($weekday_schedule_periods === '') {
throw $incorrect_schedule_exception;
}
foreach (explode(',', $weekday_schedule_periods) as $schedule_period) {
if (!preg_match('/^\s*(?<from_h>\d{1,2}):(?<from_m>\d{2})\s*-\s*(?<to_h>\d{1,2}):(?<to_m>\d{2})\s*$/',
$schedule_period, $matches)) {
throw $incorrect_schedule_exception;
}
$from_h = $matches['from_h'];
$from_m = $matches['from_m'];
$to_h = $matches['to_h'];
$to_m = $matches['to_m'];