Skip to content

Commit

Permalink
fixup! feat(routing): Support new Route attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin committed Jan 17, 2024
1 parent 84ee83e commit ff73cff
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,15 @@ foreach ($controllers as $controllerName => $stmts) {
/** @var AttributeGroup $attrGroup */
foreach ($classMethod->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->getLast() !== "Route") {
if ($attr->name->getLast() !== "Route" && $attr->name->getLast() !== "ApiRoute" && $attr->name->getLast() !== "FrontpageRoute") {
continue;
}

$key = null;
$key = match ($attr->name->getLast()) {
"Route" => null,
"ApiRoute" => "ocs",
"FrontpageRoute" => "routes",
};
$args = [
"name" => $name,
];
Expand All @@ -286,14 +290,18 @@ foreach ($controllers as $controllerName => $stmts) {
if ($arg->name !== null) {
$argName = $arg->name->name;
} else {
$argName = ["type", "verb", "url", "requirements", "defaults", "root", "postfix"][$i];
$argNames = ["verb", "url", "requirements", "defaults", "root", "postfix"];
if ($attr->name->getLast() === "Route") {
array_unshift($argNames, "type");
}
$argName = $argNames[$i];
}

if ($argName === "type" && $arg->value instanceof ClassConstFetch) {
$type = $arg->value->name->name;
$key = match ($type) {
"TYPE_FRONTPAGE" => "routes",
"TYPE_API" => "ocs",
"TYPE_FRONTPAGE" => "routes",
default => Logger::panic($name, "Unknown Route type: " . $type),
};
continue;
Expand Down

0 comments on commit ff73cff

Please sign in to comment.