Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
➕ (Dep) Add piwik/device-detector to detector user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jan 31, 2019
1 parent 7dc131b commit 24ad453
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"twig/twig": "^2.0",
"twig/extensions": "^1.5",
"symfony/validator": "^4.2",
"symfony/property-access": "^4.2"
"symfony/property-access": "^4.2",
"piwik/device-detector": "^3.11"
},
"autoload": {
"psr-4": {
Expand Down
119 changes: 118 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions framework/Http/BaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Mix\Utils\HeaderUtils;
use Mix\Utils\IpUtils;

use DeviceDetector\DeviceDetector;

/**
* Request组件基类
* @author 刘健 <coder.liu@qq.com>
Expand Down Expand Up @@ -208,6 +210,31 @@ protected function scheme()
return $this->server('request_scheme') ?: $this->header('scheme');
}

/**
* Return the client Raw User-Agent
*
* This method can read the client User Agent info form the "User-Agent" header
* when set `$detector=true` ,it will return the DeviceDetector object to
* help user quick detects devices (desktop, tablet, mobile, tv, cars, console, etc.),
* clients (browsers, feed readers, media players, PIMs, ...), operating systems,
* brands and models.
*
* @see https://github.com/matomo-org/device-detector
*
* @param bool $detector
* @return DeviceDetector|string
*/
public function getUserAgent($detector = false)
{
$userAgent = $this->header('user-agent') ?? '';
if ($detector) {
$dd = new DeviceDetector($userAgent);
$dd->parse();
return $dd;
}
return $userAgent;
}

/**
* Returns the client IP address.
*
Expand Down

0 comments on commit 24ad453

Please sign in to comment.