dolibarr 25.0.0-alpha
PermissionsBlock.class.php File Reference

Text engine for the BEGIN/END MODULEBUILDER PERMISSIONS section of a module descriptor. More...

Go to the source code of this file.

Classes

class  PermissionsBlock
 Text engine for the BEGIN/END MODULEBUILDER PERMISSIONS section of a module descriptor. More...
 

Functions

 detectRightsShapeWarnings (array $permissions)
 List the rights carrying indexes the renderer will drop.
 
 render (array $permissions)
 Render a rights array as the new content of the permissions block.
 
 assignOffsets (array $group)
 Give each right of one object its numbering offset.
 
 escapeForPhpSingleQuotedString (string $value)
 Escape a value for inclusion in a single-quoted PHP string literal.
 
 write (string $newInnerBlock)
 Replace the whole permissions block, markers included, in a single write.
 

Detailed Description

Text engine for the BEGIN/END MODULEBUILDER PERMISSIONS section of a module descriptor.

Definition in file PermissionsBlock.class.php.

Function Documentation

◆ assignOffsets()

assignOffsets ( array $group)
private

Give each right of one object its numbering offset.

The three standard crud codes keep their canonical offset. Any other code — or a duplicate standard one — takes the next free offset from 3 upwards, so two rights of the same object can never collide on the same permission id.

Parameters
array<int,array<int,string>>$group Rights of a single object
Returns
array<int,array{offset:int,right:array<int,string>}> Entries sorted by offset
Parameters
array{offset:int,right:array<int,string>}$a First entry to compare
array{offset:int,right:array<int,string>}$b Second entry to compare
Returns
int

Definition at line 287 of file PermissionsBlock.class.php.

References string.

Referenced by render().

◆ detectRightsShapeWarnings()

detectRightsShapeWarnings ( array $permissions)

List the rights carrying indexes the renderer will drop.

Indexes 2 and 3 are obsolete in modern Dolibarr. Dropping them is the correct migration, so this is reported as a warning and does not prevent the write.

Parameters
array<int,array<int,string>>$permissions Rights array to inspect
Returns
string[] Plain English warnings, empty when every right has a supported shape

Definition at line 222 of file PermissionsBlock.class.php.

◆ escapeForPhpSingleQuotedString()

escapeForPhpSingleQuotedString ( string $value)
private

Escape a value for inclusion in a single-quoted PHP string literal.

GETPOST(..., 'alpha') keeps the single quote, the semicolon, the dollar sign and parentheses, so a label reaches this class able to close the literal it is written into.

Parameters
string$valueRaw value
Returns
string Value safe to place between single quotes in generated PHP

Definition at line 331 of file PermissionsBlock.class.php.

Referenced by render().

◆ render()

render ( array $permissions)

Render a rights array as the new content of the permissions block.

Only indexes 0, 1, 4 and 5 are emitted: the historical code rewrote those four but imploded the whole row, so a right carrying the obsolete index 2 or 3 had its raw value written into the descriptor, which then no longer parsed.

Parameters
array<int,array<int,string>>$permissions Rights array to render
Returns
string Block content, markers excluded, one trailing newline

Definition at line 248 of file PermissionsBlock.class.php.

References $id, assignOffsets(), escapeForPhpSingleQuotedString(), and string.

◆ write()

write ( string $newInnerBlock)

Replace the whole permissions block, markers included, in a single write.

dolReplaceInFile() already writes to a .tmp file and dol_move()s it into place, so the write itself is atomic. What matters here is that there is exactly ONE of them: the historical code deleted the block and then inserted the new one, leaving the descriptor without any permissions block whenever the second write failed.

Regex mode is mandatory, not a style choice: in plain mode dolReplaceInFile() runs the whole file through make_substitutions(), which expands __(Key)__ and [class:method:id] patterns anywhere in the descriptor and even instantiates classes to do so.

Parameters
string$newInnerBlockNew block content, markers excluded
Returns
int 1 if OK, <0 if KO

Definition at line 351 of file PermissionsBlock.class.php.

References dol_syslog(), and dolReplaceInFile().

Referenced by dolReceiptPrinter\sendToPrinter().