alexander-suter / yii2-browser-info
Browser Information for Yii2
Installs: 2 340
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Type:yii2-extension
Requires
- browscap/browscap-php: 2.0.5
- yiisoft/yii2: 2.0.*
Requires (Dev)
- pahanini/yii2-consolelog: *
- phpunit/phpunit: 4.7.*
This package is not auto-updated.
Last update: 2024-10-26 18:06:33 UTC
README
Yii2 extension. Provides detailed information about the browser.
Current available providers:
- Browscap (https://github.com/browscap/browscap-php)
Installation
The preferred way to install this extension is through composer.
To install, either run
$ php composer.phar require alexander-suter/yii2-browser-info "*"
or add
"alexander-suter/yii2-browser-info": "*"
to the require
section of your composer.json
file.
Usage
This extensions works with a cache in the background. You have to update the cache from time to time.
Create a cronjob and execute following command:
./yii browser-info/update-cache
Use dependency injection to define the concret instance:
Yii::$container->set('asu\browserinfo\BrowserInfo', [ 'class' => 'asu\browserinfo\BrowserInfoBrowscap', 'memoryLimit' => '512M' ]);
The Browscap implementation needs much memory to update the cache.
To get browser information in a controller you can now use your DI-Definition:
class SiteController extends Controller { private $browserInfo = null; public function __construct($id, $module, BrowserInfo $browserInfo, $config = []) { $this->browserInfo = $browserInfo; parent::__construct($id, $module, $config); } public function actionIndex() { echo $this->browserInfo->getBrowserName(); } }