Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Routing] Optimised dumped router matcher, prevent unneeded function calls. #21755

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 12 commits into from
Closed
Prev Previous commit
Next Next commit
Added a test case which more clearly demonstrates the effect of the h…
…ttp method optimization, especially the HEAD case.
  • Loading branch information
frankdejonge committed Feb 27, 2017
commit 9d92c57942ece43e7ec48f7dcd8bdf967e5179d6
101 changes: 101 additions & 0 deletions 101 src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;

/**
* ProjectUrlMatcher.
*
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
/**
* Constructor.
*/
public function __construct(RequestContext $context)
{
$this->context = $context;
}

public function match($pathinfo)
{
$allow = array();
$pathinfo = rawurldecode($pathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$requestMethod = $isLikeGetMethod = $context->getMethod();
$schema = $context->getScheme();

if ($requestMethod === 'HEAD') {
$isLikeGetMethod = 'GET';
}


// just_head
if ('/just_head' === $pathinfo) {
if ('HEAD' !== $requestMethod) {
$allow[] = 'HEAD';
goto not_just_head;
}

return array('_route' => 'just_head');
}
not_just_head:

// head_and_get
if ('/head_and_get' === $pathinfo) {
if ('GET' !== $isLikeGetMethod) {
$allow[] = 'GET';
goto not_head_and_get;
}

return array('_route' => 'head_and_get');
}
not_head_and_get:

if (0 === strpos($pathinfo, '/p')) {
// post_and_head
if ('/post_and_get' === $pathinfo) {
if (!in_array($requestMethod, array('POST', 'HEAD'))) {
$allow = array_merge($allow, array('POST', 'HEAD'));
goto not_post_and_head;
}

return array('_route' => 'post_and_head');
}
not_post_and_head:

if (0 === strpos($pathinfo, '/put_and_post')) {
// put_and_post
if ('/put_and_post' === $pathinfo) {
if (!in_array($requestMethod, array('PUT', 'POST'))) {
$allow = array_merge($allow, array('PUT', 'POST'));
goto not_put_and_post;
}

return array('_route' => 'put_and_post');
}
not_put_and_post:

// put_and_get_and_head
if ('/put_and_post' === $pathinfo) {
if (!in_array($isLikeGetMethod, array('PUT', 'GET'))) {
$allow = array_merge($allow, array('PUT', 'GET'));
goto not_put_and_get_and_head;
}

return array('_route' => 'put_and_get_and_head');
}
not_put_and_get_and_head:

}

}

throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,59 @@ public function getRouteCollections()
$route->setCondition('context.getMethod() == "GET"');
$rootprefixCollection->add('with-condition', $route);

/* test case 4 */
$headMatchCasesCollection = new RouteCollection();
$headMatchCasesCollection->add('just_head', new Route(
'/just_head',
array(),
array(),
array(),
'',
array(),
array('HEAD')
));
$headMatchCasesCollection->add('head_and_get', new Route(
'/head_and_get',
array(),
array(),
array(),
'',
array(),
array('GET', 'HEAD')
));
$headMatchCasesCollection->add('post_and_head', new Route(
'/post_and_get',
array(),
array(),
array(),
'',
array(),
array('POST', 'HEAD')
));
$headMatchCasesCollection->add('put_and_post', new Route(
'/put_and_post',
array(),
array(),
array(),
'',
array(),
array('PUT', 'POST')
));
$headMatchCasesCollection->add('put_and_get_and_head', new Route(
'/put_and_post',
array(),
array(),
array(),
'',
array(),
array('PUT', 'GET', 'HEAD')
));

return array(
array($collection, 'url_matcher1.php', array()),
array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
array($rootprefixCollection, 'url_matcher3.php', array()),
array($headMatchCasesCollection, 'url_matcher4.php', array()),
);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.