Skip to content

Commit

Permalink
change the way to use regex
Browse files Browse the repository at this point in the history
  • Loading branch information
kimb0na committed Apr 28, 2023
1 parent 0cb230e commit 47f0589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
9 changes: 7 additions & 2 deletions Config/SystemConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ public function getAddSlashes(): bool
return (bool)$this->config->getValue(self::XML_ADD_SLASHES);
}

public function getEndpointToExclude(): string
public function getEndpointToExclude(): array
{
return $this->config->getValue(self::XML_ENDPOINTS_TO_EXCLUDE);
$endPoints = $this->config->getValue(self::XML_ENDPOINTS_TO_EXCLUDE);
if (null === $endPoints || '' === trim($endPoints)) {
return [];
}

return array_map("trim", preg_split('/\R/', trim($endPoints)));
}
}
16 changes: 6 additions & 10 deletions Plugin/RestApiLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,16 @@ private function parseMessage(string $message): string

private function isEndpointToExclude(string $endpoint): bool
{
$endPointsToExclude = preg_split('/\R/', $this->configuration->getEndpointToExclude());

if (!is_array($endPointsToExclude)) {
if (0 >= count($this->configuration->getEndpointToExclude())) {
return false;
}

$isEndpointToExclude = false;
foreach ($endPointsToExclude as $item) {
if (strpos($endpoint, $item) !== false) {
$isEndpointToExclude = true;
break;
}
$combinedString = implode('|', $this->configuration->getEndpointToExclude());
$combinedString = addcslashes($combinedString, '/');
if (preg_match('/(' . $combinedString . ')/i', $endpoint)) {
return true;
}

return $isEndpointToExclude;
return false;
}
}

0 comments on commit 47f0589

Please sign in to comment.