mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fully convert core to a modern module (#13347)
* Core module WIP * update OS::make() * core WIP * try to finish up * switch all core do os Model * Mock WIP * Working tests * cleanup * phpstan fixes * style fixes * fix agent * trim space too and a couple of cleanups * corrected ios test data * missed space * update test data * put escapes back * another net-snmp difference * Fix class description * revert snmp.inc.php change, that can be a different PR * revert snmp.inc.php change, that can be a different PR
This commit is contained in:
@@ -125,4 +125,25 @@ class StringHelpers
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a class name from a lowercase string containing - or _
|
||||
* Remove - and _ and camel case words
|
||||
*
|
||||
* @param string $name The string to convert to a class name
|
||||
* @param string|null $namespace namespace to prepend to the name for example: LibreNMS\
|
||||
* @return string Class name
|
||||
*/
|
||||
public static function toClass(string $name, ?string $namespace = null): string
|
||||
{
|
||||
$pre_format = str_replace(['-', '_'], ' ', $name);
|
||||
$class = str_replace(' ', '', ucwords(strtolower($pre_format)));
|
||||
$class = preg_replace_callback('/^(\d)(.)/', function ($matches) {
|
||||
$numbers = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine'];
|
||||
|
||||
return $numbers[$matches[1]] . strtoupper($matches[2]);
|
||||
}, $class);
|
||||
|
||||
return $namespace . $class;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user