Skip to content

Commit

Permalink
ensure we set the user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Jan 27, 2015
1 parent 4606f64 commit 2a370bd
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions EventListener/ThemeRequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ public function __construct(ActiveTheme $activeTheme, array $cookieOptions = nul
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
if ($this->autoDetect) {
$this->autoDetect->setUserAgent($event->getRequest()->server->get('HTTP_USER_AGENT'));
}

$cookieValue = null;
if (null !== $this->cookieOptions) {
$cookieValue = $event->getRequest()->cookies->get($this->cookieOptions['name']);
}

if (!$cookieValue && $this->autoDetect instanceof DeviceDetectionInterface) {
$cookieValue = $this->getThemeType($event->getRequest());
$cookieValue = $this->autoDetect->getType();
}

if ($cookieValue && $cookieValue !== $this->activeTheme->getName()
Expand All @@ -87,22 +91,6 @@ public function onKernelRequest(GetResponseEvent $event)
}
}

/**
* Given the Request return the device type.
*
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return string the user agent type
*/
private function getThemeType(Request $request)
{
$userAgent = $request->server->get('HTTP_USER_AGENT');
$this->autoDetect->setUserAgent($userAgent);

return $this->autoDetect->getType();
}


/**
* @param FilterResponseEvent $event
*/
Expand Down

0 comments on commit 2a370bd

Please sign in to comment.