renamed suppression message to rule.
This commit is contained in:
@@ -48,29 +48,29 @@ final class Suppressor
|
||||
{
|
||||
$params = DataUtil::fromRequest($request);
|
||||
|
||||
if (null === ($message = $params->get('message')) || empty($message)) {
|
||||
return api_error('Message text is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
if (null === ($rule = $params->get('rule')) || empty($rule)) {
|
||||
return api_error('Rule is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if (null === ($type = $params->get('type')) || empty($type)) {
|
||||
return api_error('Message type is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
return api_error('Rule type is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$type = strtolower($type);
|
||||
|
||||
if (null === ($example = $params->get('example')) || empty($example)) {
|
||||
return api_error('Message example is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
return api_error('Rule example is required.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
if ('regex' === $type) {
|
||||
if (false === @preg_match($message, '')) {
|
||||
if (false === @preg_match($rule, '')) {
|
||||
return api_error('Invalid regex pattern.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
if (false === @preg_match($message, $example)) {
|
||||
if (false === @preg_match($rule, $example)) {
|
||||
return api_error('Example does not match the regex pattern.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
} else {
|
||||
if (false === str_contains($example, $message)) {
|
||||
if (false === str_contains($example, $rule)) {
|
||||
return api_error('Example does not contain the message text.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ final class Suppressor
|
||||
|
||||
$data = [
|
||||
'type' => $type,
|
||||
'message' => $message,
|
||||
'rule' => $rule,
|
||||
'example' => $example,
|
||||
];
|
||||
|
||||
|
||||
@@ -58,18 +58,18 @@ final class LogSuppressor implements iHandler
|
||||
}
|
||||
|
||||
foreach (self::$suppress as $suppress) {
|
||||
$message = ag($suppress, 'message', '');
|
||||
if (empty($message)) {
|
||||
$rule = ag($suppress, 'rule', '');
|
||||
if (empty($rule)) {
|
||||
continue;
|
||||
}
|
||||
if ('regex' === ag($suppress, 'type', 'contains')) {
|
||||
if (1 === @preg_match($message, $log)) {
|
||||
if (1 === @preg_match($rule, $log)) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_contains($log, $message)) {
|
||||
if (str_contains($log, $rule)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ class LogSuppressorTest extends TestCase
|
||||
|
||||
private array $testData = [
|
||||
'A7434c91d3440' => [
|
||||
'message' => 'Random string',
|
||||
'rule' => 'Random string',
|
||||
'type' => 'contains',
|
||||
],
|
||||
'A7434c91d3441' => [
|
||||
'message' => '/some random \'(\d+)\'/',
|
||||
'rule' => '/some random \'(\d+)\'/',
|
||||
'type' => 'regex',
|
||||
],
|
||||
'A7434c91d3442' => [
|
||||
'message' => '',
|
||||
'rule' => '',
|
||||
'type' => 'contains',
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user