-
-
Notifications
You must be signed in to change notification settings - Fork 955
Closed
Labels
Description
Description
I like using ApiPlatform but I find the configuration painfull to set up (lack of autocompletion, no reusability, no automation, break easily without usefull warning...).
Being able to configure API platform using simple PHP class would solve these problems.
Example
function __invoke(ApiConfigurator $configurator) {
// itemOperations
$operations = array_map(function ($method) {
return (new ItemOperation(Comment::class, $method))
->setNormalizationContext(['read:comment'], 'ReadComment')
->setSecurity($method === 'GET' ? CommentVoter::READ : CommentVoter::EDIT, 'object');
;
}, ['GET','DELETE','PUT']);
$operations[] = new ItemOperation(Comment::class, 'patch');
// collection operation
$operations[] = new CollectionOperation(Comment::class, 'get')
$configurator->addOperations($operations);
}This approach solve many problems I have with the configuration right now :
- It's self documenting. It's easier to discover features reading the source code
- It's easier to automate some features using functions or custom classes.
- It's easier to detect problems when the configuration API changes using static analysis.