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