Source
<?php
/*
** 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/>.
**/
class CUserMacroParser extends CParser {
const STATE_NEW = 0;
const STATE_END = 1;
const STATE_UNQUOTED = 2;
const STATE_QUOTED = 3;
const STATE_END_OF_MACRO = 4;
public const REGEX_PREFIX = 'regex:';
private $macro = '';
private $context = null;
private $context_quoted = false;
private $regex = null;
/**
* An options array.
*
* Supported options:
* 'allow_regex' => false Enable "regex:" context prefix. This prefix should be accessible in the user macro
* configuration places (global-, template- and host-level macros) only.
*
* @var array
*/
private $options = [
'allow_regex' => false
];
/**
* @param array $options
*/
public function __construct(array $options = []) {
$this->options = $options + $this->options;
$this->error_msgs['empty'] = _('macro is empty');
$this->error_msgs['unexpected_end'] = _('unexpected end of macro');
}
/**
* @inheritDoc
*/
public function parse($source, $pos = 0) {
$this->length = 0;
$this->match = '';
$this->macro = '';
$this->context = null;
$this->context_quoted = false;
$this->errorClear();