Skip to content

Commit

Permalink
Request wird nun weitergereicht
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko Fenrich committed Jun 8, 2017
1 parent f7abbe5 commit 0f519a3
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/MiddlewareMobileDetect.php
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);
}



}

0 comments on commit 0f519a3

Please sign in to comment.