|
8 | 8 |
|
9 | 9 | # --------------------------------------------------------------------------------------------------------------- |
10 | 10 |
|
11 | | -$baseDir = dirname(dirname(__FILE__)); |
| 11 | +$baseDir = dirname(__FILE__, 2); |
12 | 12 |
|
13 | 13 | #$oldModuleId = "example-basic"; |
14 | 14 | $moduleInfo = json_decode(file_get_contents($baseDir . '/module.json'), true); |
|
30 | 30 | print "\tNew:\t" . $newModuleId . "\t(" . dashesToCamelCase($newModuleId) . ")\n"; |
31 | 31 | print "\n"; |
32 | 32 |
|
33 | | -if (strpos($newModuleId, $oldModuleId) !== false && $oldModuleId !== $newModuleId) { |
| 33 | +if (str_contains($newModuleId, (string) $oldModuleId) && $oldModuleId !== $newModuleId) { |
34 | 34 | print "Old module ID cannot be part of the new module id!\n"; |
35 | 35 | die(); |
36 | 36 | } |
37 | 37 |
|
38 | | -if (strpos($newNamespace, $oldNamespace) !== false && $oldNamespace !== $newNamespace) { |
| 38 | +if (str_contains($newNamespace, $oldNamespace) && $oldNamespace !== $newNamespace) { |
39 | 39 | print "Old module namespace cannot be part of the new namespace!\n"; |
40 | 40 | die(); |
41 | 41 | } |
|
44 | 44 | $it = new RecursiveDirectoryIterator($baseDir); |
45 | 45 | foreach (new RecursiveIteratorIterator($it) as $file) { |
46 | 46 | /** @var SplFileInfo $file */ |
47 | | - if (strpos($file, '.git') !== false || strpos($file, '.idea') !== false || $file->isDir() || $file == __FILE__) { |
| 47 | + if (str_contains($file, '.git') || str_contains($file, '.idea') || $file->isDir() || $file == __FILE__) { |
48 | 48 | continue; |
49 | 49 | } |
50 | 50 |
|
51 | 51 | // Replace in files |
52 | 52 | $fileContent = file_get_contents($file); |
53 | 53 | $fileContent = str_replace($oldNamespace, $newNamespace, $fileContent); |
54 | 54 | $fileContent = str_replace($oldModuleId, $newModuleId, $fileContent); |
55 | | - $fileContent = str_replace(ucfirst($oldModuleId), ucfirst($newModuleId), $fileContent); |
| 55 | + $fileContent = str_replace(ucfirst((string) $oldModuleId), ucfirst($newModuleId), $fileContent); |
56 | 56 | $fileContent = str_replace(dashesToCamelCase($oldModuleId), dashesToCamelCase($newModuleId), $fileContent); |
57 | 57 | $fileContent = str_replace(ucfirst(dashesToCamelCase($oldModuleId)), ucfirst(dashesToCamelCase($newModuleId)), $fileContent); |
58 | 58 | file_put_contents($file, $fileContent); |
59 | 59 | print "Searched&replaced in: " . $file . "\n"; |
60 | 60 |
|
61 | 61 | // Rename file names (e.g. resources/js/humhub.example-basic.js) |
62 | | - if (strpos($file->getBasename(), $oldModuleId) !== false) { |
| 62 | + if (str_contains($file->getBasename(), (string) $oldModuleId)) { |
63 | 63 | $newFileName = $file->getPath() . '/' . str_replace($oldModuleId, $newModuleId, $file->getBasename()); |
64 | 64 |
|
65 | 65 | rename($file, $newFileName); |
|
72 | 72 | */ |
73 | 73 | function camelCaseToDashed($className): string |
74 | 74 | { |
75 | | - return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $className)); |
| 75 | + return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', (string) $className)); |
76 | 76 | } |
77 | 77 |
|
78 | 78 | function dashesToCamelCase($string, $capitalizeFirstCharacter = false): string |
|
0 commit comments