Skip to content

Commit

Permalink
Merge pull request #22 from netlogix/fix/matchingstatuscodes-position
Browse files Browse the repository at this point in the history
fix: Sort NodeBasedConfiguration by length of pathPrefixes
  • Loading branch information
stephanschuler authored Oct 29, 2024
2 parents 45e35c3 + 429fba0 commit dbfc89c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Classes/Command/ErrorPageCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function generateCommand(bool $verbose = false)
public function showConfigurationCommand()
{
$result = [
'Neltogix' => [
'Netlogix' => [
'ErrorHandler' => [
'pages' => $this->configuration->getConfiguration()
]
Expand Down
12 changes: 11 additions & 1 deletion Classes/Configuration/NodeBasedConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public function getConfiguration(): array
$this->throwableStorage->logThrowable($e);
}
}

usort($configurationsForSite[$sitename], fn($a, $b) => $a['position'] <=> $b['position']);
$configurationsForSite[$sitename] = array_map(fn($item) => array_diff_key($item, ['position' => 0]), $configurationsForSite[$sitename]);
$configurationsForSite[$sitename] = array_values($configurationsForSite[$sitename]);
}

Expand All @@ -111,13 +114,20 @@ public function getConfiguration(): array

public function getErrorNodeConfiguration(NodeInterface $errorNode): array
{
$pathPrefixes = $this->extractPathPrefixes($errorNode);
$position = 1000;
foreach ($pathPrefixes as $pathPrefix) {
$position -= strlen($pathPrefix);
}

return [
'matchingStatusCodes' => $this->extractStatusCodes($errorNode),
'dimensions' => $this->extractDimensions($errorNode),
'dimensionPathSegment' => $this->extractDimensionsPathSegment($errorNode),
'source' => '#' . $errorNode->getIdentifier(),
'destination' => $this->destination,
'pathPrefixes' => $this->extractPathPrefixes($errorNode),
'pathPrefixes' => $pathPrefixes,
'position' => $position,
];
}

Expand Down

0 comments on commit dbfc89c

Please sign in to comment.