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 18, 2024
1 parent 489320f commit 96a0588
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -255,54 +255,54 @@ foreach ($controllers as $controllerName => $stmts) {
$controllerClass = null;
/** @var Class_ $class */
foreach ($nodeFinder->findInstanceOf($stmts, Class_::class) as $class) {
if ($class->name->name === $controllerName . "Controller") {
if ($class->name->name === $controllerName . 'Controller') {
$controllerClass = $class;
break;
}
}
if ($controllerClass === null) {
Logger::error($controllerName, "Controller '" . $controllerName . "' not found");
Logger::error($controllerName, "Controller '$controllerName' not found");
continue;
}

/** @var ClassMethod $classMethod */
foreach ($nodeFinder->findInstanceOf($controllerClass->stmts, ClassMethod::class) as $classMethod) {
$name = substr($class->name->name, 0, -10) . "#" . $classMethod->name->name;
$name = substr($class->name->name, 0, -10) . '#' . $classMethod->name->name;

/** @var AttributeGroup $attrGroup */
foreach ($classMethod->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->getLast() !== "Route" && $attr->name->getLast() !== "ApiRoute" && $attr->name->getLast() !== "FrontpageRoute") {
if ($attr->name->getLast() !== 'Route' && $attr->name->getLast() !== 'ApiRoute' && $attr->name->getLast() !== 'FrontpageRoute') {
continue;
}

$key = match ($attr->name->getLast()) {
"Route" => null,
"ApiRoute" => "ocs",
"FrontpageRoute" => "routes",
'Route' => null,
'ApiRoute' => 'ocs',
'FrontpageRoute' => 'routes',
};
$args = [
"name" => $name,
'name' => $name,
];
for ($i = 0, $iMax = count($attr->args); $i < $iMax; $i++) {
$arg = $attr->args[$i];

if ($arg->name !== null) {
$argName = $arg->name->name;
} else {
$argNames = ["verb", "url", "requirements", "defaults", "root", "postfix"];
if ($attr->name->getLast() === "Route") {
array_unshift($argNames, "type");
$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) {
if ($argName === 'type' && $arg->value instanceof ClassConstFetch) {
$type = $arg->value->name->name;
$key = match ($type) {
"TYPE_API" => "ocs",
"TYPE_FRONTPAGE" => "routes",
default => Logger::panic($name, "Unknown Route type: " . $type),
'TYPE_API' => 'ocs',
'TYPE_FRONTPAGE' => 'routes',
default => Logger::panic($name, 'Unknown Route type: ' . $type),
};
continue;
}
Expand Down

0 comments on commit 96a0588

Please sign in to comment.