Skip to content

[Routing] Expose request in route conditions, if needed and possible #22636

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

[Routing] Expose request in route conditions, if needed and possible #22636

wants to merge 2 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented May 4, 2017

Q A
Branch? 2.7
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #16968, #22635
License MIT
Doc PR -

given

/**
 * @Route("/", name="homepage", condition="request.isXmlHttpRequest()")
 */
$ app/console route:match /

before

image

after

image

@javiereguiluz
Copy link
Member

I don't know if it's possible to change it, but don't you think that the error message in this case should be a yellow warning with this message?

Route "homepage" may match if condition "request.isXmlHttpRequest()" evaluates to true.

@ro0NL
Copy link
Contributor Author

ro0NL commented May 7, 2017

It's possible... sure ;-) but perhaps out-of-scope for now.

The part after almost matches but ... comes from the traces log.. so im not really sure what i get myself into, in terms of other variants.

Also if (TraceableUrlMatcher::ROUTE_ALMOST_MATCHES == $trace['level']) { is quite explicit... im not sure it covers "may match" :)

{
return class_exists('Symfony\Component\HttpFoundation\Request')
? Request::create($this->context->getScheme().'://'.$this->context->getHost().$this->context->getBaseUrl().$pathinfo, $this->context->getMethod(), $this->context->getParameters())
: null;
Copy link
Member

Choose a reason for hiding this comment

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

should be on one line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do 👍 i also realized the request is probably not fully functional now; it needs some server params so it can properly resolve baseurl + basepath and such. I wanted to look at that this weekend :)

@ro0NL
Copy link
Contributor Author

ro0NL commented May 14, 2017

@fabpot this should do.

@@ -248,4 +248,16 @@ protected function getExpressionLanguage()

return $this->expressionLanguage;
}

protected function createRequest($pathinfo)
Copy link
Member

Choose a reason for hiding this comment

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

this should be private IMHO

Copy link
Member

Choose a reason for hiding this comment

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

hum, @internal in fact

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone May 15, 2017
@fabpot
Copy link
Member

fabpot commented Jun 14, 2017

Thank you @ro0NL.

fabpot added a commit that referenced this pull request Jun 14, 2017
…d possible (ro0NL)

This PR was squashed before being merged into the 2.7 branch (closes #22636).

Discussion
----------

[Routing] Expose request in route conditions, if needed and possible

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16968, #22635
| License       | MIT
| Doc PR        | -

given

```
/**
 * @route("/", name="homepage", condition="request.isXmlHttpRequest()")
 */
```

```
$ app/console route:match /
```

before

![image](https://cloud.githubusercontent.com/assets/1047696/25716808/b9ab518e-3100-11e7-8b59-21351b5c14ca.png)

after

![image](https://cloud.githubusercontent.com/assets/1047696/25716833/d08065fc-3100-11e7-9462-987b2c6eaa26.png)

Commits
-------

016e976 [Routing] Expose request in route conditions, if needed and possible
@fabpot fabpot closed this Jun 14, 2017
@fabpot
Copy link
Member

fabpot commented Jun 14, 2017

Thank you @ro0NL.

fabpot added a commit that referenced this pull request Jun 14, 2017
…d and possible (ro0NL)

This PR was squashed before being merged into the 2.7 branch (closes #22636).

Discussion
----------

[Routing] Expose request in route conditions, if needed and possible

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16968, #22635
| License       | MIT
| Doc PR        | -

given

```
/**
 * @route("/", name="homepage", condition="request.isXmlHttpRequest()")
 */
```

```
$ app/console route:match /
```

before

![image](https://cloud.githubusercontent.com/assets/1047696/25716808/b9ab518e-3100-11e7-8b59-21351b5c14ca.png)

after

![image](https://cloud.githubusercontent.com/assets/1047696/25716833/d08065fc-3100-11e7-9462-987b2c6eaa26.png)

Commits
-------

94371d0 [Routing] Expose request in route conditions, if needed and possible
@ro0NL ro0NL deleted the urlmatcher-request branch July 12, 2017 15:53
This was referenced Oct 18, 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.

5 participants