dolibarr 24.0.0-beta
NamingContract.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 ATM Consulting <support@atm-consulting.fr>
3 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
36final class NamingContract
37{
39 public $moduleNameCase;
40
42 public $moduleNameLower;
43
45 public $moduleNameUpper;
46
48 public $objectNameCase;
49
51 public $objectNameLower;
52
54 public $objectNameUpper;
55
61 public function __construct(string $moduleName, string $objectName = '')
62 {
63 $this->moduleNameCase = ucfirst($moduleName);
64 $this->moduleNameLower = strtolower($moduleName);
65 $this->moduleNameUpper = strtoupper($moduleName);
66
67 if ($objectName === '') {
68 $this->objectNameCase = '';
69 $this->objectNameLower = '';
70 $this->objectNameUpper = '';
71 return;
72 }
73
74 if (strtolower($moduleName) === strtolower($objectName)) {
75 throw new \InvalidArgumentException(
76 'Module and object names cannot be identical (case-insensitive match): "'
77 . $moduleName . '" vs "' . $objectName . '"'
78 );
79 }
80
81 $this->objectNameCase = ucfirst($objectName);
82 $this->objectNameLower = strtolower($objectName);
83 $this->objectNameUpper = strtoupper($objectName);
84 }
85
95 public function getSubstitutionMap(): array
96 {
97 $map = [
98 'MYMODULE' => $this->moduleNameUpper,
99 'MyModule' => $this->moduleNameCase,
100 'My module' => $this->moduleNameCase,
101 'my module' => $this->moduleNameLower,
102 'Mon module' => $this->moduleNameCase,
103 'mon module' => $this->moduleNameLower,
104 'mymodule' => $this->moduleNameLower,
105 ];
106
107 if ($this->objectNameLower !== '') {
108 $map['MYOBJECT'] = $this->objectNameUpper;
109 $map['MyObject'] = $this->objectNameCase;
110 $map['My Object'] = $this->objectNameCase;
111 $map['my object'] = $this->objectNameLower;
112 $map['myobject'] = $this->objectNameLower;
113 }
114
115 return $map;
116 }
117
124 public function applyTo(string $content): string
125 {
126 $map = $this->getSubstitutionMap();
127 return str_replace(array_keys($map), array_values($map), $content);
128 }
129
139 public function applyToFilename(string $filename): string
140 {
141 $search = ['mymodule'];
142 $replace = [$this->moduleNameLower];
143
144 if ($this->objectNameLower !== '') {
145 $search[] = 'myobject';
146 $replace[] = $this->objectNameLower;
147 }
148
149 return str_replace($search, $replace, $filename);
150 }
151}
Immutable value object holding all case variants of a module/object pair.
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).
__construct(string $moduleName, string $objectName='')
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php