Skip to content

Commit fb82c9e

Browse files
committed
refactor(routing): Allow unknown routes.php formats
Signed-off-by: provokateurin <[email protected]>
1 parent 6283132 commit fb82c9e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Route.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ public function __construct(
2222

2323
public static function parseRoutes(string $path): array {
2424
$content = file_get_contents($path);
25-
if (str_contains($content, "return ")) {
26-
if (str_contains($content, "\$this")) {
27-
preg_match("/return ([^;]*);/", $content, $matches);
28-
return self::includeRoutes("<?php\nreturn " . $matches[1] . ";");
25+
if (str_contains($content, 'return ')) {
26+
if (str_contains($content, '$this')) {
27+
preg_match('/return ([^;]*);/', $content, $matches);
28+
return self::includeRoutes("<?php\nreturn ${matches[1]};");
2929
}
3030
return include($path);
31-
} elseif (str_contains($content, "registerRoutes")) {
32-
preg_match_all("/registerRoutes\(.*?\\\$this,.*?(\[[^;]*)\);/s", $content, $matches);
33-
return array_merge(...array_map(fn (string $match) => self::includeRoutes("<?php\nreturn " . $match . ";"), $matches[1]));
34-
} else {
35-
Logger::panic("Routes", "Unknown routes.php format");
31+
} elseif (str_contains($content, 'registerRoutes')) {
32+
preg_match_all('/registerRoutes\(.*?\$this,.*?(\[[^;]*)\);/s', $content, $matches);
33+
return array_merge(...array_map(fn (string $match) => self::includeRoutes("<?php\nreturn $match;"), $matches[1]));
3634
}
35+
36+
Logger::warning('Routes', 'Unknown routes.php format');
37+
return [];
3738
}
3839

3940
private static function includeRoutes(string $code): array {

0 commit comments

Comments
 (0)