dolibarr 24.0.0-beta
NamingContract Class Reference

Immutable value object holding all case variants of a module/object pair. More...

Public Member Functions

 __construct (string $moduleName, string $objectName='')
 
 getSubstitutionMap ()
 Returns the canonical, ordered substitution map.
 
 applyTo (string $content)
 Apply the canonical substitution map to a string (file content).
 
 applyToFilename (string $filename)
 Apply substitution to a filename (lowercase tokens only).
 

Detailed Description

Immutable value object holding all case variants of a module/object pair.

Provides the canonical, ordered substitution map used by modulebuilder template generation. The substitution order in getSubstitutionMap() is deterministic: uppercase and mixed-case tokens always precede lowercase ones, preventing partial matches when str_replace processes entries sequentially on the same string.

applyTo() uses str_replace() directly — NOT make_substitutions() — to avoid unintended processing of Dolibarr's __(key)__ and [key] patterns present in raw template content.

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

Constructor & Destructor Documentation

◆ __construct()

NamingContract::__construct ( string $moduleName,
string $objectName = '' )
Parameters
string$moduleNameRaw module name — accepts any casing, ucfirst() is applied
string$objectNameRaw object name — empty string creates a module-only contract
Exceptions

InvalidArgumentException If module and object names are identical (case-insensitive)

Definition at line 61 of file NamingContract.class.php.

Member Function Documentation

◆ applyTo()

NamingContract::applyTo ( string $content)

Apply the canonical substitution map to a string (file content).

Parameters
string$contentFile content to process
Returns
string Content with substitutions applied

Definition at line 124 of file NamingContract.class.php.

References getSubstitutionMap().

◆ applyToFilename()

NamingContract::applyToFilename ( string $filename)

Apply substitution to a filename (lowercase tokens only).

Filenames in Dolibarr are always lowercase — only mymodule/myobject are substituted. For module-only contracts (objectNameLower = ''), myobject is not substituted.

Parameters
string$filenameTemplate filename containing mymodule/myobject placeholders
Returns
string File name with substitutions applied

Definition at line 139 of file NamingContract.class.php.

◆ getSubstitutionMap()

NamingContract::getSubstitutionMap ( )

Returns the canonical, ordered substitution map.

Order matters: uppercase and mixed-case tokens precede lowercase tokens so that str_replace sequential processing cannot partially consume a longer token variant. Object tokens (positions 8–12) are omitted for module-only contracts (objectName = '').

Returns
array<string, string>

Definition at line 95 of file NamingContract.class.php.

Referenced by applyTo().


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