Commit 90b4be53 authored by Fabien Potencier's avatar Fabien Potencier

merged branch fabpot/request-context-fix (PR #663)

This PR was merged into the master branch.

Discussion
----------

fixed request dependency on the URL matcher

Alternative fix for #662

Commits
-------

5dc7c27f fixed request dependency on the URL matcher
parents 08f08ea6 5dc7c27f
......@@ -28,7 +28,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Silex\RequestContext;
use Silex\RedirectableUrlMatcher;
use Silex\ControllerResolver;
use Silex\EventListener\LocaleListener;
......@@ -125,11 +125,6 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
});
$this['url_matcher'] = $this->share(function () use ($app) {
// Inject the query string into the RequestContext for Symfony versions <= 2.2
if ($app['request']->server->get('QUERY_STRING') !== '' && !method_exists($app['request_context'], 'getQueryString')) {
$app['request_context']->setParameter('QUERY_STRING', $app['request']->server->get('QUERY_STRING'));
}
return new RedirectableUrlMatcher($app['routes'], $app['request_context']);
});
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Routing\RequestContext as BaseRequestContext;
use Symfony\Component\HttpFoundation\Request;
/**
* Request Context for Symfony <= 2.2
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestContext extends BaseRequestContext
{
public function fromRequest(Request $request)
{
parent::fromRequest($request);
// Inject the query string as a parameter for Symfony versions <= 2.2
if (!method_exists($this, 'getQueryString') && '' !== $qs = $request->server->get('QUERY_STRING')) {
$this->setParameter('QUERY_STRING', $qs);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment