Skip to content

Commit

Permalink
Improve routeList method
Browse files Browse the repository at this point in the history
  • Loading branch information
realodix committed May 8, 2024
1 parent 0001711 commit fca0778
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public static function urlDisplay(
}

/**
* List of potentially colliding routes with shortened link keywords
*
* @return array<string>
*/
public static function routeList(): array
Expand All @@ -78,8 +80,17 @@ public static function routeList(): array
);

return collect($route)
// ex. admin/{any} => admin
->map(fn ($value) => preg_replace('/(\/){.+/', '', $value))
// ex. foobar/{route_param?} => foobar
->map(fn ($value) => preg_replace('/(\/{)([a-zA-Z]+)(\?})$/', '', $value))
// Remove foo/bar
->map(fn ($value) => preg_replace('/^([a-zA-Z-_]+)\/([a-zA-Z-\/{}\.]+)/', '', $value))
// Remove '{route_param}' or '+{route_param}'
->map(fn ($value) => preg_replace('/^(\+?)({)([a-zA-Z]+)(})/', '', $value))
// Remove '/'
->map(fn ($value) => preg_replace('/\//', '', $value))
// Remove empty value
->reject(fn ($value) => empty($value))
->unique()
->toArray();
}
}

0 comments on commit fca0778

Please sign in to comment.