-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mirko Fenrich
committed
Jun 8, 2017
1 parent
f7abbe5
commit 0f519a3
Showing
1 changed file
with
21 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,47 @@ | ||
<?php | ||
namespace Depa\MiddlewareMobileDetect; | ||
|
||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Interop\Http\ServerMiddleware\MiddlewareInterface; | ||
use Interop\Http\ServerMiddleware\DelegateInterface; | ||
use Detection\MobileDetect; | ||
|
||
|
||
|
||
class MiddlewareMobileDetect implements MiddlewareInterface | ||
{ | ||
|
||
/** | ||
* | ||
* @var MobileDetect | ||
*/ | ||
private $detector; | ||
|
||
//private $attributes = array('client-isMobile'=>false,'client-isTablet'=>false,'client-isiOS'=>false,'client-isAndroidOS'=>false); | ||
|
||
// private $attributes = array('client-isMobile'=>false,'client-isTablet'=>false,'client-isiOS'=>false,'client-isAndroidOS'=>false); | ||
public function __construct() | ||
{ | ||
$this->detector = new MobileDetect(); | ||
$this->detector = new MobileDetect(); | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* {@inheritdoc} | ||
* | ||
* @see \Interop\Http\ServerMiddleware\MiddlewareInterface::process() | ||
*/ | ||
public function process(ServerRequestInterface $request, DelegateInterface $delegate) | ||
{ | ||
if($this->detector->isMobile()){ | ||
$request->withAttribute('client-isMobile', TRUE); | ||
} | ||
if($this->detector->isTablet()){ | ||
$request->withAttribute('client-isTablet', TRUE); | ||
} | ||
if($this->detector->isiOS()){ | ||
$request->withAttribute('client-isiOS', TRUE); | ||
} | ||
if($this->detector->isiAndroidOS()){ | ||
$request->withAttribute('client-isAndroidOS', TRUE); | ||
} | ||
|
||
return $delegate->process($request); | ||
if ($this->detector->isMobile()) { | ||
$request = $request->withAttribute('client-isMobile', TRUE); | ||
} | ||
if ($this->detector->isTablet()) { | ||
$request = $request->withAttribute('client-isTablet', TRUE); | ||
} | ||
if ($this->detector->isiOS()) { | ||
$request = $request->withAttribute('client-isiOS', TRUE); | ||
} | ||
if ($this->detector->isiAndroidOS()) { | ||
$request = $request->withAttribute('client-isAndroidOS', TRUE); | ||
} | ||
|
||
return $delegate->process($request); | ||
} | ||
|
||
|
||
|
||
} |