Is your feature request related to a problem? Please describe.
When multiple web services need the same group of parameters (e.g., address fields, pagination fields, date range fields), the parameter definitions must be duplicated in each service constructor. This violates DRY and makes updates error-prone (change in one place, forget the others).
Describe the solution you'd like
A ParameterSet base class that groups related parameters:
class AddressParams extends ParameterSet {
public function getParameters(): array {
return [
['name' => 'street', 'type' => 'string', 'min-length' => 5],
['name' => 'city', 'type' => 'string'],
['name' => 'zip', 'type' => 'string', 'pattern' => '/^[0-9]{5}$/'],
['name' => 'country', 'type' => 'string', 'allowed-values' => ['US', 'UK', 'DE']],
];
}
}
class PaginationParams extends ParameterSet {
public function getParameters(): array {
return [
['name' => 'page', 'type' => 'integer', 'min-val' => 1, 'optional' => true, 'default' => 1],
['name' => 'per_page', 'type' => 'integer', 'min-val' => 1, 'max-val' => 100, 'optional' => true, 'default' => 20],
];
}
}
Usage in services:
class CreateOrderService extends WebService {
public function __construct() {
parent::__construct('create-order');
$this->addParameterSet(new AddressParams()); // street, city, zip, country
$this->addParameterSet(new AddressParams(), 'billing_'); // billing_street, billing_city, ...
$this->addParameter(['name' => 'total', 'type' => 'double']);
}
}
class ListUsersService extends WebService {
public function __construct() {
parent::__construct('list-users');
$this->addParameterSet(new PaginationParams());
}
}
addParameterSet(ParameterSet $set, string $prefix = ''):
- Iterates
$set->getParameters()
- Prepends
$prefix to each parameter name
- Calls
addParameter() for each
Describe alternatives you'd considered
- Trait with parameter definitions (traits can't be parameterized with prefix)
- Helper methods that return arrays (works but no type safety, no IDE support)
- Inheritance (CreateOrderService extends AddressService — wrong relationship)
Additional context
Depends on #114 (allowed-values and pattern) for the full feature set in parameter definitions. The ParameterSet class itself is ~20 lines — it's just a container for parameter definition arrays.
Is your feature request related to a problem? Please describe.
When multiple web services need the same group of parameters (e.g., address fields, pagination fields, date range fields), the parameter definitions must be duplicated in each service constructor. This violates DRY and makes updates error-prone (change in one place, forget the others).
Describe the solution you'd like
A
ParameterSetbase class that groups related parameters:Usage in services:
addParameterSet(ParameterSet $set, string $prefix = ''):$set->getParameters()$prefixto each parameter nameaddParameter()for eachDescribe alternatives you'd considered
Additional context
Depends on #114 (allowed-values and pattern) for the full feature set in parameter definitions. The
ParameterSetclass itself is ~20 lines — it's just a container for parameter definition arrays.