nmdimas/yii2-user-agent-parser

The user agent parser for the Yii framework (Yii2)

Installs: 4 358

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 1

Forks: 3

Type:yii2-extension

1.0 2015-07-23 13:20 UTC

This package is not auto-updated.

Last update: 2024-12-25 10:26:52 UTC


README

Build Status HHVM Status

This extension adds support for PhpUserAgent(https://github.com/donatj/PhpUserAgent) to the Yii2 framework.

Installation

'components' => [
      ...
      'userAgentParser' => [
          'class' => 'yii\useragentparser\UserAgentParser',
          'nameHttpPropertyUserAgent' => 'HTTP_USER_AGENT'
      ],
      ...
  ],

Usage

If we parse current request

$userAgentInfo = Yii::$app->userAgentParser->getUserAgentObject();

or need parse isset user-agent

$userAgentInfo = Yii::$app->userAgentParser->getUserAgentObject($userAgent);

$userAgentInfo it's UserAgentObject with properties:

  • userAgent
  • platform
  • browser
  • version

Best practices

Add to Yii.php in root for autocompletion for custom components.

 /** @property  \yii\useragentparser\UserAgentParser $userAgentParser */

About autocompletion for custom components.

https://github.com/samdark/yii2-cookbook/blob/master/book/ide-autocompletion.md