symfony-cmf / routing-auto-bundle

Adding automatic route generating on top of the symfony cmf routing
https://cmf.symfony.com
14 stars 29 forks source link

Matching different controller for each HTTP method #196

Open damienflament opened 7 years ago

damienflament commented 7 years ago

I want to match a different controller action for each HTTP method on a single URI. The nicest way to do this might be:

App\Document\Page:
    uri_schema: /{title}
    definitions:
        view:
            methods: [GET]
            defaults:
                _controller: App:Page:view
        edit:
            methods: [PATCH]
            defaults:
                _controller: App:Page:edit
    token_poviders:
        title: [content_method, {method: getTitle}]

As the _urischema key is validated by the YmlFileLoader but not handled as a mapping key, I tried this:

 App\Document\Page:
    definitions:
        view:
            uri_schema: /{title}
            methods: [GET]
            defaults:
                _controller: App:Page:view
        edit:
            uri_schema: /{title}
            methods: [PATCH]
            defaults:
                _controller: App:Page:edit
    token_poviders:
        title: [content_method, {method: getTitle}]

But the methods key is not handled.

What's the good way to add HTTP method requirements like with the standard Symfony router ?

dantleech commented 7 years ago

Looks like a valid feature to me. Feel free to PR - you will just have to add the key to the loader(s) and ensure that the (PHPCR-ODM) adapter persists the method on the Route object (which already has a method setMethods(array $methods) iirc)