mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Prevent function collisions with Laravel (#8166)
Make function call compatible drop insensitive starts_with and ends_with for now as they aren't needed.
This commit is contained in:
committed by
Neil Lathwood
parent
1ee7d51f7a
commit
b2762d9fa7
@@ -1385,83 +1385,78 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!function_exists('str_contains')) {
|
||||
/**
|
||||
* Determine if a given string contains a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function str_contains($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ($needle != '' && strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string contains a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @param bool $case_insensitive
|
||||
* @return bool
|
||||
*/
|
||||
function str_contains($haystack, $needles, $case_insensitive = false)
|
||||
function str_i_contains($haystack, $needles)
|
||||
{
|
||||
if ($case_insensitive) {
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ($needle != '' && stripos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ($needle != '' && strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ($needle != '' && stripos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string ends with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @param bool $case_insensitive
|
||||
* @return bool
|
||||
*/
|
||||
function ends_with($haystack, $needles, $case_insensitive = false)
|
||||
{
|
||||
if ($case_insensitive) {
|
||||
$lower_haystack = strtolower($haystack);
|
||||
foreach ((array)$needles as $needle) {
|
||||
if (strtolower($needle) === substr($lower_haystack, -strlen($needle))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!function_exists('ends_with')) {
|
||||
/**
|
||||
* Determine if a given string ends with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function ends_with($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ((string)$needle === substr($haystack, -strlen($needle))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string starts with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @param bool $case_insensitive
|
||||
* @return bool
|
||||
*/
|
||||
function starts_with($haystack, $needles, $case_insensitive = false)
|
||||
{
|
||||
if ($case_insensitive) {
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ($needle != '' && stripos($haystack, $needle) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!function_exists('starts_with')) {
|
||||
/**
|
||||
* Determine if a given string starts with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function starts_with($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ($needle != '' && strpos($haystack, $needle) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_auth_ad_user_filter($username)
|
||||
|
@@ -1005,7 +1005,7 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
|
||||
if (!is_numeric($tmp_value)) {
|
||||
if ($sensor_type === 'temperature') {
|
||||
// For temp sensors, try and detect fahrenheit values
|
||||
if (ends_with($tmp_value, 'f', true)) {
|
||||
if (ends_with($tmp_value, array('f', 'F'))) {
|
||||
$user_function = 'fahrenheit_to_celsius';
|
||||
}
|
||||
}
|
||||
|
@@ -1069,12 +1069,12 @@ function is_port_valid($port, $device)
|
||||
$ifAlias = $port['ifAlias'];
|
||||
$ifType = $port['ifType'];
|
||||
|
||||
if (str_contains($ifDescr, Config::getOsSetting($device['os'], 'good_if'), true)) {
|
||||
if (str_i_contains($ifDescr, Config::getOsSetting($device['os'], 'good_if'))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (Config::getCombined($device['os'], 'bad_if') as $bi) {
|
||||
if (str_contains($ifDescr, $bi, true)) {
|
||||
if (str_i_contains($ifDescr, $bi)) {
|
||||
d_echo("ignored by ifDescr: $ifDescr (matched: $bi)\n");
|
||||
return false;
|
||||
}
|
||||
|
@@ -420,7 +420,7 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra
|
||||
list($mib, $file) = explode(':', $mib_name_table, 2);
|
||||
|
||||
if (is_null($rrd_name)) {
|
||||
if (str_contains($mib_name_table, 'UBNT', true)) {
|
||||
if (str_i_contains($mib_name_table, 'UBNT')) {
|
||||
$rrd_name = strtolower($mib);
|
||||
} else {
|
||||
$rrd_name = strtolower($file);
|
||||
|
Reference in New Issue
Block a user