🌐 AI搜索 & 代理 主页
Skip to content

[RFC] PHP based configuration #3558

@Grafikart

Description

@Grafikart

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions