Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DependencyInjection/MobileDetectExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace SunCat\MobileDetectBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* DI extension
Expand Down
2 changes: 1 addition & 1 deletion DeviceDetector/MobileDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* MobileDetector class
*
* Extend Mobile_Detect
* Extends Mobile_Detect
*
* @author suncat2000 <nikolay.kotovsky@gmail.com>
*
Expand Down
45 changes: 24 additions & 21 deletions EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(Container $serviceContainer, array $redirectConf, $
}

/**
* Handle Request
* Handles the Request
*
* @param GetResponseEvent $event
*
Expand All @@ -68,19 +68,19 @@ public function __construct(Container $serviceContainer, array $redirectConf, $
public function handleRequest(GetResponseEvent $event)
{

// Set flag for response handle by GET switch param and type of view
// Sets the flag for the response handled by the GET switch param and the type of the view.
if ($this->deviceView->hasSwitchParam()) {
$event->setResponse($this->getRedirectResponseBySwitchParam());

return;
}

// If full view or not mobile
// If the device view is either the the full view or not the mobile view
if ($this->deviceView->isFullView() || $this->deviceView->isNotMobileView()) {
return;
}

// Redirect to tablet version and set 'tablet' device view (in cookie)
// Redirects to the tablet version and set the 'tablet' device view in a cookie.
if ($this->hasTabletRedirect()) {
if (($response = $this->getTabletRedirectResponse())) {
$event->setResponse($response);
Expand All @@ -89,7 +89,7 @@ public function handleRequest(GetResponseEvent $event)
return;
}

// Redirect to mobile version and set 'mobile' device view (in cookie)
// Redirects to the mobile version and set the 'mobile' device view in a cookie.
if ($this->hasMobileRedirect()) {

if (($response = $this->getMobileRedirectResponse())) {
Expand All @@ -99,25 +99,26 @@ public function handleRequest(GetResponseEvent $event)
return;
}

// If not redirects
// Set flag for response handle and generate closure
// No need to redirect

// Sets the flag for the response handler
$this->needModifyResponse = true;

// Set closure modifier tablet Response
// Checking the need to modify the Response and set closure
if ($this->needTabletResponseModify()) {
$this->deviceView->setTabletView();

return;
}

// Set closure modifier mobile Response
// Sets the closure modifier mobile Response
if ($this->needMobileResponseModify()) {
$this->deviceView->setMobileView();

return;
}

// Set closure modifier not_mobile Response
// Sets the closure modifier not_mobile Response
if ($this->needNotMobileResponseModify()) {
$this->deviceView->setNotMobileView();

Expand All @@ -127,7 +128,7 @@ public function handleRequest(GetResponseEvent $event)
}

/**
* Handle Response
* Handles the Response
*
* @param FilterResponseEvent $event
*
Expand All @@ -144,7 +145,7 @@ public function handleResponse(FilterResponseEvent $event)
}

/**
* Detect mobile redirect
* Detects mobile redirections.
*
* @return boolean
*/
Expand All @@ -166,7 +167,7 @@ private function hasMobileRedirect()
}

/**
* Detect tablet redirect
* Detects tablet redirections.
*
* @return boolean
*/
Expand All @@ -187,7 +188,7 @@ private function hasTabletRedirect()
}

/**
* If need modify Response for tablet
* If a modified Response for tablet devices is needed
*
* @return boolean
*/
Expand All @@ -208,7 +209,7 @@ private function needTabletResponseModify()
}

/**
* If need modify Response for tablet
* If a modified Response for mobile devices is needed
*
* @return boolean
*/
Expand All @@ -228,7 +229,7 @@ private function needMobileResponseModify()
}

/**
* If need modify Response for non mobile device
* If a modified Response for non-mobile devices is needed.
*
* @return boolean
*/
Expand All @@ -246,7 +247,7 @@ private function needNotMobileResponseModify()
}

/**
* Get RedirectResponse by switch param
* Gets the RedirectResponse by switch param.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
Expand All @@ -263,7 +264,7 @@ private function getRedirectResponseBySwitchParam()
}

/**
* Get mobile RedirectResponse
* Gets the mobile RedirectResponse.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
Expand All @@ -278,7 +279,7 @@ private function getMobileRedirectResponse()
}

/**
* Get tablet RedirectResponse
* Gets the tablet RedirectResponse.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
Expand All @@ -293,7 +294,7 @@ private function getTabletRedirectResponse()
}

/**
* Get redirest url
* Gets the redirect url.
*
* @param string $platform
*
Expand All @@ -312,7 +313,7 @@ private function getRedirectUrl($platform)
}

/**
* Gets named option from current route
* Gets named option from current route.
*
* @param string $name
*
Expand Down Expand Up @@ -341,6 +342,8 @@ private function getRoutingOption($name)
}

/**
* Gets the current host.
*
* @return string
*/
private function getCurrentHost()
Expand Down
51 changes: 25 additions & 26 deletions Helper/DeviceView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

namespace SunCat\MobileDetectBundle\Helper;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\DependencyInjection\Container;

use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
use SunCat\MobileDetectBundle\Helper\RedirectResponseWithCookie;

/**
Expand All @@ -35,7 +34,7 @@ class DeviceView
private $viewType;

/**
* Construct
* Constructor
*
* @param \Symfony\Component\DependencyInjection\Container $serviceContainer
*/
Expand All @@ -57,7 +56,7 @@ public function __construct(Container $serviceContainer)
}

/**
* Get view type for device
* Gets the view type for a device.
*
* @return string
*/
Expand All @@ -67,81 +66,81 @@ public function getViewType()
}

/**
* Is full view type for device
* Is the device in full view.
*
* @return boolean
*/
public function isFullView()
{
return ($this->viewType == self::VIEW_FULL);
return $this->viewType === self::VIEW_FULL;
}

/**
* Is tablet view type for device
* Is the device a tablet view type.
*
* @return boolean
*/
public function isTabletView()
{
return ($this->viewType == self::VIEW_TABLET);
return $this->viewType === self::VIEW_TABLET;
}

/**
* Is mobile view type for device
* Is the device a mobile view type.
*
* @return boolean
*/
public function isMobileView()
{
return ($this->viewType == self::VIEW_MOBILE);
return $this->viewType === self::VIEW_MOBILE;
}

/**
* Is not mobile view type for device (PC, Mac ...)
* Is not the device a mobile view type (PC, Mac, etc.).
*
* @return boolean
*/
public function isNotMobileView()
{
return ($this->viewType == self::VIEW_NOT_MOBILE);
return $this->viewType === self::VIEW_NOT_MOBILE;
}

/**
* Has switch param in query string (GET)
* Has the Request the switch param in the query string (GET header).
*
* @return boolean
*/
public function hasSwitchParam()
{
return ($this->request->query->has(self::SWITCH_PARAM));
return $this->request->query->has(self::SWITCH_PARAM);
}

/**
* Set tablet view type
* Sets the tablet view type.
*/
public function setTabletView()
{
$this->viewType = self::VIEW_TABLET;
}

/**
* Set mobile view type
* Sets the mobile view type.
*/
public function setMobileView()
{
$this->viewType = self::VIEW_MOBILE;
}

/**
* Set not mobile view type
* Sets the not mobile view type.
*/
public function setNotMobileView()
{
$this->viewType = self::VIEW_NOT_MOBILE;
}

/**
* Get switch param value from query string (GET)
* Gets the switch param value from the query string (GET header).
*
* @return string
*/
Expand All @@ -151,7 +150,7 @@ public function getSwitchParamValue()
}

/**
* Get RedirectResponsy by switch param value
* Gets the RedirectResponse by switch param value.
*
* @param string $redirectUrl
*
Expand All @@ -172,7 +171,7 @@ public function getRedirectResponseBySwitchParam($redirectUrl)
}

/**
* Modify Response for not mobile device
* Modifies the Response for non-mobile devices.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
Expand All @@ -186,7 +185,7 @@ public function modifyNotMobileResponse(Response $response)
}

/**
* Modify Response for tablet device
* Modifies the Response for tablet devices.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
Expand All @@ -200,7 +199,7 @@ public function modifyTabletResponse(Response $response)
}

/**
* Modify Response for mobile device
* Modifies the Response for mobile devices.
*
* @param \Symfony\Component\HttpFoundation\Response $response
*
Expand All @@ -214,7 +213,7 @@ public function modifyMobileResponse(Response $response)
}

/**
* Get RedirectResponse for tablet
* Gets the RedirectResponse for tablet devices.
*
* @param string $host Uri host
* @param int $statusCode Status code
Expand All @@ -227,7 +226,7 @@ public function getTabletRedirectResponse($host, $statusCode)
}

/**
* Get RedirectResponse for mobile
* Gets the RedirectResponse for mobile devices.
*
* @param string $host Uri host
* @param int $statusCode Status code
Expand All @@ -240,7 +239,7 @@ public function getMobileRedirectResponse($host, $statusCode)
}

/**
* Get cookie
* Gets the cookie.
*
* @param string $cookieValue
*
Expand Down
Loading