dolibarr 25.0.0-alpha
PredicateRule.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 PredicateRule implements AccessRuleExpression
30{
31 const TYPE = 'predicate';
32
33 const IS_ADMIN = 'isAdmin';
34 const IS_INTERNAL_USER = 'isInternalUser';
35 const CAN_READ_OBJECT = 'canReadObject';
36 const CAN_WRITE_OBJECT = 'canWriteObject';
37 const CAN_DELETE_OBJECT = 'canDeleteObject';
38
43 const PREDICATES = array(
44 self::IS_ADMIN => '!empty($user->admin)',
45 self::IS_INTERNAL_USER => 'empty($user->socid)',
46 self::CAN_READ_OBJECT => "\$user->hasRight('mymodule', 'myobject', 'read')",
47 self::CAN_WRITE_OBJECT => "\$user->hasRight('mymodule', 'myobject', 'write')",
48 self::CAN_DELETE_OBJECT => "\$user->hasRight('mymodule', 'myobject', 'delete')",
49 );
50
52 private $name;
53
58 public function __construct(string $name)
59 {
60 if (!array_key_exists($name, self::PREDICATES)) {
61 throw new \InvalidArgumentException('Unknown access rule predicate: '.$name);
62 }
63 $this->name = $name;
64 }
65
69 public function getName(): string
70 {
71 return $this->name;
72 }
73
79 public function toPhp(): string
80 {
81 return self::PREDICATES[$this->name];
82 }
83
87 public function toArray(): array
88 {
89 return array('type' => self::TYPE, 'name' => $this->name);
90 }
91}
Leaf of the access rule tree: one whitelisted condition on the user.
__construct(string $name)
toPhp()
Render the predicate as a PHP boolean expression.
const PREDICATES
PHP rendered for each predicate.
Node of the access rule tree of the pages generated by ModuleBuilder.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:165