8000 [RFC][HttpFoundation] Introduce RequestMatcher as a namespace by ro0NL · Pull Request #20274 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RFC][HttpFoundation] Introduce RequestMatcher as a namespace #20274

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 2 commits into from
Closed

[RFC][HttpFoundation] Introduce RequestMatcher as a namespace #20274

wants to merge 2 commits into from

Conversation

ro0NL
Copy link
Contributor
@ro0NL ro0NL commented Oct 22, 2016
Q A
Branch? "master"
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes/no
Fixed tickets comma-separated list of tickets fixed by the PR, if any
License MIT
Doc PR reference to the documentation PR, if any

Idea is to have many simple request matchers instead of several complex ones (allowing to built complex ones from simple ones) and make them immutable.

@carsonbot carsonbot added Status: Needs Review RFC RFC = Request For Comments (proposals about features that you want to be discussed) HttpFoundation Feature Deprecation labels Oct 22, 2016
@fabpot
Copy link
Member
fabpot commented Nov 10, 2016

I don't see which problems it solves. Request matchers should stay quite simple.

@ro0NL
Copy link
Contributor Author
ro0NL commented Nov 10, 2016

Maybe it's a bridge too far, but personally i would like to be able to write a request matcher as follow;

class MyMatcher extends ChainMatcher {
   public function __construct() {
      parent::__construct([
          new MethodMatcher(['GET', 'POST']),
          new PathMatchher('/some-path'),
      ]);
   }
}

Or be able to just use a path matcher, if path matching is the only case (opposed to the full generic request matcher we have now). From my experience things like access_control uses only path matching 9/10 times. Imo. that should built a chain matcher based on given configs.., ie.

$matchers = [];
if (isset($config['path'])
   $matchers[] = new PathMatcher($config['path']);
}
// etc.

$matcher = 1 === count($matchers) ? reset($matchers) : new ChainMatcher($matchers);

It makes things simple, clean and reuseable on a very low level. However, my true interest goes to #20272, which made me think about this approach.

The current (generic) request matcher would be just a built-in chain request matcher.

Please close, if you dont think this is viable or over-engineered.

{
$matchers = array();
if (null !== $path) {
$matchers[] = new PathRequestMatcher($path, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to make it even more reusable it would be nice to be able to inject custom matchers:

    /**
     * @param RequestMatcherInferace|string|null $path
     * @param RequestMatcherInferace|string|null $host
     * @param RequestMatcherInferace|string[]    $methods
     * @param RequestMatcherInferace|string[]    $ips
     * @param RequestMatcherInferace|array       $attributes
     * @param RequestMatcherInferace|string[]    $schemes
     */
    public function __construct($path = null, $host = null, array $methods = array(), array $ips,  array(), array $attributes = array(), array $schemes = array())
    {
        $matchers = array();
        if (null !== $path) {
            $matchers[] = $path instanceof RequestMatcherInterface ? $path : new PathRequestMatcher($path, true);
        }

        // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure.. to me this class just factorizes a chain matcher (from scalars). If you have ready-to-use matchers, just chain them yourself 😕

And eventually the entire class may not be needed, if we built a chain in the security extension from config.

Same for the current ExpressionRequestMatcher, which extends the (current) generic request matcher and integrates the EL component additionally. Now we have 2 generic request matchers... 😕

With this PR i propse a standalone expression request matcher, which you can combine with other matchers (using a chain).

*/
public function __construct(array $matchers)
{
$this->matchers = $matchers;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should loop through the matchers and maybe use a public add or addMatcher() which throws an invalid argument exception when it does not implement the RequestMatcherInterface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 not sure about a add method though, making the class mutable. I tend to like having immutable matchers by default.

@nicolas-grekas
< 8000 /svg> Copy link
Member

👎: a request is a single semantic unit of path+host+method+ips+scheme+etc. Having a single matcher just matches this unit.

@ro0NL
Copy link
Contributor Author
ro0NL commented Dec 29, 2016

Closing in favor of #21029, only this wont change much.

@ro0NL ro0NL closed this Dec 29, 2016
@ro0NL ro0NL deleted the http-foundation/request-matchers branch December 29, 2016 08:42
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Feature HttpFoundation RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0