Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Commit

Permalink
merged branch fabpot/request-context-fix (PR #663)
Browse files Browse the repository at this point in the history
This PR was merged into the master branch.

Discussion
----------

fixed request dependency on the URL matcher

Alternative fix for #662

Commits
-------

5dc7c27 fixed request dependency on the URL matcher
  • Loading branch information
fabpot committed Apr 1, 2013
2 parents 08f08ea + 5dc7c27 commit 90b4be5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/Silex/Application.php
Expand Up @@ -28,7 +28,7 @@
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;
Expand Down Expand Up @@ -125,11 +125,6 @@ public function __construct(array $values = array())
});

$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']);
});

Expand Down
33 changes: 33 additions & 0 deletions src/Silex/RequestContext.php
@@ -0,0 +1,33 @@
<?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);
}
}
}

0 comments on commit 90b4be5

Please sign in to comment.