Source
if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE || $expression['expression_type'] == EXPRESSION_TYPE_FALSE) {
<?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 for regular expressions and Zabbix global expressions.
* Any string that begins with '@' is treated as Zabbix expression.
* Data from Zabbix expressions is taken from DB, and cached in static variable.
*
* @throws Exception
*/
class CGlobalRegexp {
const ERROR_REGEXP_NOT_EXISTS = 1;
/**
* Determine if it's Zabbix expression.
*
* @var bool
*/
protected $isZabbixRegexp;
/**
* If we create simple regular expression this contains itself as a string,
* if we create Zabbix expression this contains array of expressions taken from DB.
*
* @var array|string
*/
protected $expression;
/**
* Cache for Zabbix expressions.
*
* @var array
*/
private static $_cachedExpressions = [];
/**
* Initialize expression, gets data from db for Zabbix expressions.
*
* @param string $regExp
*
* @throws Exception
*/
public function __construct($regExp) {
if ($regExp[0] == '@') {
$this->isZabbixRegexp = true;
$regExp = substr($regExp, 1);
if (!isset(self::$_cachedExpressions[$regExp])) {
self::$_cachedExpressions[$regExp] = [];