Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
10 / 10 |
| MobileDetectPlugin | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
10 / 10 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| __invoke | |
100.00% |
1 / 1 |
3 | |
100.00% |
8 / 8 |
|||
| <?php | |
| namespace Neilime\MobileDetect\Mvc\Controller\Plugin; | |
| use Zend\Mvc\Controller\Plugin\AbstractPlugin; | |
| class MobileDetectPlugin extends AbstractPlugin | |
| { | |
| /** | |
| * @var \Mobile_Detect | |
| */ | |
| protected $mobileDetect; | |
| /** | |
| * @param \Mobile_Detect $mobileDetect | |
| */ | |
| public function __construct(\Mobile_Detect $mobileDetect) | |
| { | |
| $this->mobileDetect = $mobileDetect; | |
| } | |
| /** | |
| * Retrieve Mobile-detect service | |
| * | |
| * @param \Zend\Http\Headers $oHeaders | |
| * | |
| * @throws \LogicException | |
| * @return \Mobile_Detect | |
| */ | |
| public function __invoke(\Zend\Http\Headers $oHeaders = null) | |
| { | |
| $oController = $this->getController(); | |
| if (!$oController) { | |
| throw new \LogicException('Controller is undefined for MobileDetect controller plugin'); | |
| } | |
| if ($oHeaders) { | |
| $this->mobileDetect->setHttpHeaders($oHeaders->toArray()); | |
| $this->mobileDetect->setUserAgent($oHeaders->get('user-agent')->getFieldValue()); | |
| } | |
| return $this->mobileDetect; | |
| } | |
| } |