dolibarr 25.0.0-alpha
OrRule.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 ATM Consulting <support@atm-consulting.fr>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT.'/modulebuilder/class/AccessRuleExpression.class.php';
25
29final class OrRule implements AccessRuleExpression
30{
31 const TYPE = 'or';
32
34 private $rules;
35
40 public function __construct(array $rules)
41 {
42 if (empty($rules)) {
43 throw new \InvalidArgumentException('An access rule or node requires at least one rule');
44 }
45 foreach ($rules as $rule) {
46 if (!$rule instanceof AccessRuleExpression) {
47 throw new \InvalidArgumentException('An access rule or node only accepts access rule nodes');
48 }
49 }
50 $this->rules = array_values($rules);
51 }
52
56 public function getRules(): array
57 {
58 return $this->rules;
59 }
60
66 public function toPhp(): string
67 {
68 $parts = array();
69 foreach ($this->rules as $rule) {
70 $parts[] = $rule->toPhp();
71 }
72 return '('.implode(' || ', $parts).')';
73 }
74
78 public function toArray(): array
79 {
80 $rules = array();
81 foreach ($this->rules as $rule) {
82 $rules[] = $rule->toArray();
83 }
84 return array('type' => self::TYPE, 'rules' => $rules);
85 }
86}
Disjunction node of the access rule tree: met when at least one of its rules is met.
toPhp()
Render the rules as a PHP boolean expression joined by ||, wrapped in parentheses.
__construct(array $rules)
Node of the access rule tree of the pages generated by ModuleBuilder.