dolibarr 25.0.0-alpha
AccessPolicyConfig Class Reference

Immutable access policy of the pages generated by ModuleBuilder: a rule tree and a deny message. More...

Collaboration diagram for AccessPolicyConfig:

Public Member Functions

 __construct (AccessRuleExpression $expression, string $message='')
 
 toJson ()
 Serialize the policy.
 
 getExpression ()
 
 getMessage ()
 

Static Public Member Functions

static fromAlternatives (array $alternatives, string $message='')
 Build a policy from the editor of ModuleBuilder: the predicates of an alternative are combined with AND, the alternatives with OR.
 
static fromJson (string $json)
 Load a serialized policy, as produced by toJson().
 

Static Private Member Functions

static buildNode ($data, int $depth)
 Build a node of the tree from its serialized form.
 
static checkBounds (AccessRuleExpression $node, int $depth, int &$nodecount)
 Check that a tree stays within MAX_DEPTH and MAX_NODES.
 

Detailed Description

Immutable access policy of the pages generated by ModuleBuilder: a rule tree and a deny message.

A policy is always valid once built: every way in (constructor, fromJson(), fromAlternatives()) rejects an unknown node, an unknown predicate, a tree out of bounds or a message that is not a translation key.

Definition at line 36 of file AccessPolicyConfig.class.php.

Constructor & Destructor Documentation

◆ __construct()

AccessPolicyConfig::__construct ( AccessRuleExpression $expression,
string $message = '' )
Parameters
AccessRuleExpression$expressionRoot of the rule tree
string$messageTranslation key shown on deny, empty for the default message
Exceptions

InvalidArgumentException When the tree is out of bounds or the message is not a translation key

Definition at line 54 of file AccessPolicyConfig.class.php.

References checkBounds().

Member Function Documentation

◆ buildNode()

static AccessPolicyConfig::buildNode ( $data,
int $depth )
staticprivate

Build a node of the tree from its serialized form.

Parameters
mixed$dataSerialized node
int$depthDepth of the node, 1 for the root
Returns
AccessRuleExpression The node built
Exceptions

InvalidArgumentException When the node is invalid or too deep

Definition at line 163 of file AccessPolicyConfig.class.php.

References buildNode().

Referenced by buildNode(), and fromJson().

◆ checkBounds()

static AccessPolicyConfig::checkBounds ( AccessRuleExpression $node,
int $depth,
int & $nodecount )
staticprivate

Check that a tree stays within MAX_DEPTH and MAX_NODES.

Parameters
AccessRuleExpression$nodeNode to check
int$depthDepth of the node, 1 for the root
int$nodecountNumber of nodes met so far, updated
Returns
void
Exceptions

InvalidArgumentException When the tree is out of bounds

Definition at line 201 of file AccessPolicyConfig.class.php.

References checkBounds().

Referenced by __construct(), and checkBounds().

◆ fromAlternatives()

static AccessPolicyConfig::fromAlternatives ( array $alternatives,
string $message = '' )
static

Build a policy from the editor of ModuleBuilder: the predicates of an alternative are combined with AND, the alternatives with OR.

Empty alternatives are ignored.

Parameters
array<int,string[]>$alternatives List of alternatives, each one a list of predicate names
string$messageTranslation key shown on deny
Returns
AccessPolicyConfig|null Null when no predicate is selected at all
Exceptions

InvalidArgumentException When there are too many alternatives or a predicate is unknown

Definition at line 75 of file AccessPolicyConfig.class.php.

◆ fromJson()

static AccessPolicyConfig::fromJson ( string $json)
static

Load a serialized policy, as produced by toJson().

Parameters
string$jsonSerialized policy
Returns
AccessPolicyConfig The loaded policy
Exceptions

InvalidArgumentException When the content is not a valid policy

Definition at line 112 of file AccessPolicyConfig.class.php.

References buildNode().

Referenced by getModuleBuilderAccessPolicyFromClassFile().

◆ getExpression()

AccessPolicyConfig::getExpression ( )
Returns
AccessRuleExpression Root of the rule tree

Definition at line 142 of file AccessPolicyConfig.class.php.

◆ getMessage()

AccessPolicyConfig::getMessage ( )
Returns
string Translation key shown on deny, empty for the default message

Definition at line 150 of file AccessPolicyConfig.class.php.

Referenced by renderModuleBuilderAccessPolicyBlock().

◆ toJson()

AccessPolicyConfig::toJson ( )

Serialize the policy.

The order of the rules is kept, so the output is deterministic.

Returns
string Serialized policy, in JSON

Definition at line 134 of file AccessPolicyConfig.class.php.

Referenced by renderModuleBuilderAccessPolicyProperty().


The documentation for this class was generated from the following file: