Skip to content

Commit

Permalink
Fix getRouteOption + only handle master requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Roel Sint committed Jun 4, 2013
1 parent a72dd58 commit 444e595
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Route;

/**
* Request listener
Expand Down Expand Up @@ -67,6 +69,10 @@ public function __construct(Container $serviceContainer, array $redirectConf, $
*/
public function handleRequest(GetResponseEvent $event)
{
// only handle master request, do not handle sub request like esi includes
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}

// Sets the flag for the response handled by the GET switch param and the type of the view.
if ($this->deviceView->hasSwitchParam()) {
Expand Down Expand Up @@ -321,14 +327,17 @@ private function getRedirectUrl($platform)
*/
private function getRoutingOption($name)
{
$option = null;
$route = $this
->container
->get('router')
->getRouteCollection()
->get($this->container->get('request')->get('_route'))
;

$option = $route->getOption($name);
if ($route instanceof Route) {
$option = $route->getOption($name);
}

if (!$option) {
$option = $this->redirectConf[$name]['action'];
Expand All @@ -338,7 +347,7 @@ private function getRoutingOption($name)
return $option;
}

return false;
return null;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ services:
class: %mobile_detect.request_listener.class%
arguments: [ '@service_container', %mobile_detect.redirect%, %mobile_detect.switch_device_view.save_referer_path% ]
tags:
- { name: kernel.event_listener, event: kernel.request, method: handleRequest }
# must be registered after the Router to have access to the _route, and after the Symfony LocaleListener
- { name: kernel.event_listener, event: kernel.request, method: handleRequest, priority: 1 }
- { name: kernel.event_listener, event: kernel.response, method: handleResponse }
mobile_detect.twig.extension:
class: %mobile_detect.twig.extension.class%
Expand Down

0 comments on commit 444e595

Please sign in to comment.