Yii2 extension for user agent parser
, (*1)
This extension adds support for PhpUserAgent(https://github.com/donatj/PhpUserAgent) to the Yii2 framework., (*2)
Installation
'components' => [
...
'userAgentParser' => [
'class' => 'yii\useragentparser\UserAgentParser',
'nameHttpPropertyUserAgent' => 'HTTP_USER_AGENT'
],
...
],
Usage
If we parse current request, (*3)
$userAgentInfo = Yii::$app->userAgentParser->getUserAgentObject();
or need parse isset user-agent, (*4)
$userAgentInfo = Yii::$app->userAgentParser->getUserAgentObject($userAgent);
$userAgentInfo it's UserAgentObject with properties:
- userAgent
- platform
- browser
- version, (*5)
Best practices
Add to Yii.php in root for autocompletion for custom components., (*6)
/** @property \yii\useragentparser\UserAgentParser $userAgentParser */
About autocompletion for custom components., (*7)
https://github.com/samdark/yii2-cookbook/blob/master/book/ide-autocompletion.md, (*8)