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:
Tony Murray
2021-10-19 15:43:43 -05:00
committed by GitHub
parent 17b97abbd2
commit f94f7f23b8
24 changed files with 639 additions and 503 deletions

View File

@@ -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;
}
}