Problem Statement
When using #[ResponseBody] with method parameter injection, the framework resolves parameters by the PHP variable name, not the registered request parameter name. This breaks for any hyphenated parameter name (which is the standard convention in WebFiori).
Steps to Reproduce
#[RestController('my-service')]
class MyService extends WebService {
#[GetMapping]
#[ResponseBody]
#[AllowAnonymous]
#[RequestParam(name: 'app-id', type: ParamType::INT)]
public function myMethod(int $appId): Json {
// $appId is always null
return new Json(['id' => $appId]);
}
}
Calling with ?app-id=5 results in $appId being null (or a TypeError if not nullable).
Root Cause
In WebService::getMethodParameters():
foreach ($reflection->getParameters() as $param) {
$paramName = $param->getName(); // returns 'appId' (PHP variable name)
$value = $this->getParamVal($paramName); // looks for 'appId', but param is registered as 'app-id'
$params[] = $value;
}
The PHP variable name appId doesn't match the registered request parameter name app-id, so getParamVal() returns null.
Expected Behavior
The framework should convert the camelCase PHP variable name to the hyphenated form (e.g., appId → app-id) before calling getParamVal(), or try both forms. This is consistent with how WebFiori uses hyphens as the convention for parameter and column names throughout.
Workaround
Access hyphenated params manually inside the method body:
public function myMethod(string $username): Json {
$appId = $this->getParamVal('app-id'); // works
// ...
}
Only non-hyphenated params (like username) can be injected as method parameters.
Problem Statement
When using
#[ResponseBody]with method parameter injection, the framework resolves parameters by the PHP variable name, not the registered request parameter name. This breaks for any hyphenated parameter name (which is the standard convention in WebFiori).Steps to Reproduce
Calling with
?app-id=5results in$appIdbeingnull(or a TypeError if not nullable).Root Cause
In
WebService::getMethodParameters():The PHP variable name
appIddoesn't match the registered request parameter nameapp-id, sogetParamVal()returnsnull.Expected Behavior
The framework should convert the camelCase PHP variable name to the hyphenated form (e.g.,
appId→app-id) before callinggetParamVal(), or try both forms. This is consistent with how WebFiori uses hyphens as the convention for parameter and column names throughout.Workaround
Access hyphenated params manually inside the method body:
Only non-hyphenated params (like
username) can be injected as method parameters.