diff --git a/composer.json b/composer.json index 9f2909b..957a830 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,7 @@ "latte/latte" : "~2.3", - "mobiledetect/mobiledetectlib" : "2.8.*" + "jenssegers/agent" : "~2.5" }, "require-dev": { diff --git a/src/IPub/MobileDetect/DI/MobileDetectExtension.php b/src/IPub/MobileDetect/DI/MobileDetectExtension.php index 84c5475..48a5ec5 100644 --- a/src/IPub/MobileDetect/DI/MobileDetectExtension.php +++ b/src/IPub/MobileDetect/DI/MobileDetectExtension.php @@ -74,7 +74,8 @@ final class MobileDetectExtension extends DI\CompilerExtension 'path' => '/', 'secure' => FALSE, 'httpOnly' => TRUE, - ] + ], + 'debugger' => '%debugMode%' ]; /** @@ -88,7 +89,7 @@ public function loadConfiguration() $configuration = $this->getConfig($this->defaults); // Install mobile detect service - $builder->addDefinition($this->prefix('mobileDetect')) + $mobileDetect = $builder->addDefinition($this->prefix('mobileDetect')) ->setClass(MobileDetect\MobileDetect::class); $builder->addDefinition($this->prefix('deviceView')) @@ -106,6 +107,13 @@ public function loadConfiguration() 'httpOnly' => $configuration['deviceViewCookie']['httpOnly'], ]); + if ($configuration['debugger'] && interface_exists('Tracy\IBarPanel')) { + $builder->addDefinition($this->prefix('panel')) + ->setClass('IPub\MobileDetect\Diagnostics\Panel'); + + $mobileDetect->addSetup('?->register(?)', [$this->prefix('@panel'), '@self']); + } + $builder->addDefinition($this->prefix('onRequestHandler')) ->setClass(Events\OnRequestHandler::class) ->addSetup('$redirectConf', [$configuration['redirect']]) diff --git a/src/IPub/MobileDetect/Diagnostics/Panel.php b/src/IPub/MobileDetect/Diagnostics/Panel.php new file mode 100644 index 0000000..191f1a0 --- /dev/null +++ b/src/IPub/MobileDetect/Diagnostics/Panel.php @@ -0,0 +1,84 @@ + + */ +final class Panel extends \Nette\Object implements \Tracy\IBarPanel +{ + /** @var \IPub\MobileDetect\MobileDetect + */ + private $mobileDetect; + + public function register(\IPub\MobileDetect\MobileDetect $mobileDetect) + { + $this->mobileDetect = $mobileDetect; + + \Tracy\Debugger::getBar()->addPanel($this, 'ipub.mobileDetect'); + + return $this; + } + + /** + * Renders HTML code for custom tab. + * + * @return string + */ + public function getTab() + { + return '' + . $this->mobileDetect->view() . ' / ' . $this->mobileDetect->platform() . ''; + } + + /** + * Renders HTML code for custom panel. + * + * @return string + */ + public function getPanel() + { + $h = 'htmlSpecialChars'; + + $panel = []; + + $panel[] = '
' . $h($this->mobileDetect->getUserAgent()) . '
'; + + $properties = ['view', 'platform', 'platformVersion', 'device', 'browser', 'browserVersion']; + + $panel[] = '' . ucfirst($property) . ' | ' . $h($this->mobileDetect->{$property}() ?: '') . ' |
---|