Skip to content

Commit 25daf55

Browse files
committed
check types
1 parent 9ceb3b1 commit 25daf55

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

example.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Buffer\BuffLog\Bufflog;
66

77
// putenv("LOG_VERBOSITY=WARNING");
8-
BuffLog::debug("I am a debug");
8+
BuffLog::debug("I am a debug string");
99
BuffLog::debug("I am a debug with context", ["my key" => " my value"]);
1010

1111
BuffLog::info("I am an info");

src/BuffLog/BuffLog.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,40 @@ public static function __callStatic($methodName, $args)
110110
if (in_array($methodName, array_merge(self::$logOutputMethods, self::$extraAllowedMethods))) {
111111

112112
if (in_array($methodName, self::$logOutputMethods)) {
113-
// Where the magic happen. We "proxy" functions name with arguments to the Monolog instance
114-
return call_user_func_array(array(self::getLogger(), $methodName), $args);
113+
114+
if (self::checkLogParametersType($args)) {
115+
// Where the magic happen. We "proxy" functions name with arguments to the Monolog instance
116+
return call_user_func_array(array(self::getLogger(), $methodName), $args);
117+
}
115118
}
116119
} else {
117120
error_log("BuffLog::$methodName() is not supported yet. Add it to the BuffLog whitelist to allow it");
118121
}
119122
} else {
120123
error_log("BuffLog::$methodName() method does not exist");
121124
}
125+
126+
return false;
127+
}
128+
129+
private static function checkLogParametersType($args)
130+
{
131+
if (count($args) > 2) {
132+
error_log("BuffLog: Too many parameters");
133+
return false;
134+
}
135+
136+
if (isset($args[0]) && !is_string($args[0])) {
137+
error_log("BuffLog: First parameter must be a string");
138+
return false;
139+
}
140+
141+
if (isset($args[1]) && !is_array($args[1])) {
142+
error_log("BuffLog: Second parameter must be an array");
143+
return false;
144+
}
145+
146+
return true;
122147
}
123148

124149
}

0 commit comments

Comments
 (0)