Skip to content

Commit

Permalink
Merge pull request #116 from kbond/symfony-2.4
Browse files Browse the repository at this point in the history
Make router compatible with Symfony 2.4+
  • Loading branch information
schmittjoh committed Dec 5, 2013
2 parents 81be331 + b487694 commit c58e4d9
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions Router/I18nRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

use JMS\I18nRoutingBundle\Exception\NotAcceptableLanguageException;

use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\HttpFoundation\Request;

/**
* I18n Router implementation.
Expand All @@ -47,7 +49,7 @@ class I18nRouter extends Router
* since it is declared private in the parent class.
*
* The parameters are not listed explicitly here because they are different for
* Symfony 2.0 and 2.1. If we did list them, it would make this class incompatible
* Symfony 2.0 and 2.1. If we did list them, it would make this class incompatible
* with one of both versions.
*/
public function __construct()
Expand Down Expand Up @@ -158,8 +160,38 @@ public function generate($name, $parameters = array(), $absolute = false)
*/
public function match($url)
{
$params = $this->getMatcher()->match($url);
return $this->matchI18n(parent::match($url), $url);
}

public function getRouteCollection()
{
$collection = parent::getRouteCollection();

return $this->container->get($this->i18nLoaderId)->load($collection);
}

public function getOriginalRouteCollection()
{
return parent::getRouteCollection();
}

/**
* To make compatible with Symfony <2.4
*/
public function matchRequest(Request $request)
{
$matcher = $this->getMatcher();
$pathInfo = $request->getPathInfo();
if (!$matcher instanceof RequestMatcherInterface) {
// fallback to the default UrlMatcherInterface
return $this->matchI18n($matcher->match($pathInfo), $pathInfo);
}

return $this->matchI18n($matcher->matchRequest($request), $pathInfo);
}

private function matchI18n(array $params, $url)
{
if (false === $params) {
return false;
}
Expand Down Expand Up @@ -251,16 +283,4 @@ public function match($url)

return $params;
}

public function getRouteCollection()
{
$collection = parent::getRouteCollection();

return $this->container->get($this->i18nLoaderId)->load($collection);
}

public function getOriginalRouteCollection()
{
return parent::getRouteCollection();
}
}

1 comment on commit c58e4d9

@stof
Copy link

@stof stof commented on c58e4d9 Dec 9, 2013

Choose a reason for hiding this comment

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

@schmittjoh you should tag a stable version so that people upgrading to Symfony 2.4 can get this fix without having to whitelist dev versions of the bundle

Please sign in to comment.