Skip to content

[WIP] [HttpKernel] added phpdoc information support for the argument resolver #20036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Sep 23, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR not yet

The idea is to be able to write argument resolvers that needs more information that a type hint can provide today. Think an array of objects. PHPDocs can convey this information.

With the following method signature, we would have everything we need:

   /**
     * @param Post[] $posts
     */
    public function indexAction($posts, $page)
    {
    }

We would also need to take care of caching this information to avoid too much overhead. But first, I wanted to see if there is some interest.

With this support, I would then be able to support something along the lines of:

   /**
     * @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated")
     * @param Post[] $posts
     * @Arg("posts", expr="repository.findLatest(page)")
     */
    public function indexAction($posts, $page)
    {
    }

ping @iltar, @weaverryan

@fabpot fabpot changed the title [HttpKernel] added phpdoc information support for the argument resolver [WIP] [HttpKernel] added phpdoc information support for the argument resolver Sep 23, 2016
@fabpot fabpot force-pushed the argument-resolver-plus branch from 9e93ad3 to 245db53 Compare September 23, 2016 18:25
@fabpot
Copy link
Member Author

fabpot commented Sep 23, 2016

See sensiolabs/SensioFrameworkExtraBundle#436 for my plan to remove ParamConverters and replace them with configurable argument resolvers.

@linaori
Copy link
Contributor

linaori commented Sep 23, 2016

Would this also bring support for fooAction(string $foo, Post ...$post)? I'm not sure if isArray() is the correct naming though, what about isCollection() or isTypedArray()? When I think of isArray(), I'd think of array $foo, which can already be deduced from the type.

I love the expansion though, will be a great addition. Regarding the performance for annotation reading, is this going to be cached away? What about the doctrine annotations? As they are a pretty important thing for the ParamConverters.

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016
@fabpot fabpot force-pushed the argument-resolver-plus branch from 245db53 to c506a11 Compare March 22, 2017 00:27
@nicolas-grekas
Copy link
Member

Do we still need this now that we have seamless service injection?
At least, the second example could be rewritten as:

   /**
     * @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="blog_index_paginated")
     */
    public function indexAction(PostRepository $repos, $page)
    {
        $posts = $repos->findLatest($page);
    }

I'd prefer this vs putting code in an annotation. Are there any other cases?

@linaori
Copy link
Contributor

linaori commented May 5, 2017

@nicolas-grekas while that example seems very nice, it has 3 drawbacks:

  1. I have to manually call the repository and implement what happens if it can't be found in each and every action.
  2. I have to add a lot more config, as I rely on the automatic conversion of the parameter converter, which is 0 config in the current state.
  3. I can't do @Security("VIEW_PAGE", page)

@fabpot
Copy link
Member Author

fabpot commented Oct 1, 2017

I'm closing this one as I won't have time to work on it in the coming months. If someone wants to take over, feel free to do so.

@fabpot fabpot closed this Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy