├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Exceptions │ └── IdentifyException.php ├── Facades │ └── IdentityFacade.php ├── Identify.php └── IdentifyServiceProvider.php └── tests ├── IdentifyServiceProviderTest.php └── IdentifyTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | .DS_Store 3 | composer.lock -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.2 5 | 6 | matrix: 7 | allow_failures: 8 | - php: hhvm 9 | 10 | install: travis_retry composer install --no-interaction --prefer-source 11 | 12 | script: 13 | - mkdir -p build/logs 14 | - php vendor/bin/phpunit -c phpunit.xml.dist 15 | - phpunit --coverage-text --coverage-clover=coverage.clover 16 | - phpunit --coverage-clover build/logs/clover.xml 17 | 18 | after_script: 19 | - wget https://scrutinizer-ci.com/ocular.phar 20 | - php ocular.phar code-coverage:upload --format=php-clover coverage.clover 21 | - travis_retry php vendor/bin/coveralls -v 22 | 23 | notifications: 24 | slack: red-creek:5lI8ybvl6YTcCNPosh4TE13h -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `laravel-identify` will be documented in this file 4 | 5 | ## Jan 19, 2016 6 | - Initial release 7 | 8 | ## May 6, 2019 9 | - Add support for Laravel 5.3, 5.4 10 | - Bump Browser Detector to v6 11 | 12 | ## May 7, 2019 13 | - Add support for Laravel 5.5, 5.6, 5.7 and 5.8 14 | - Add support for Laravel auto package discovery -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/unicodeveloper/laravel-imanee). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. 17 | 18 | - **Create feature branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. 23 | 24 | 25 | ## Running Tests 26 | 27 | ``` bash 28 | $ composer test 29 | ``` 30 | 31 | 32 | **Happy coding**! 33 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Prosper Otemuyiwa 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-identify 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/unicodeveloper/laravel-identify/v/stable.svg)](https://packagist.org/packages/unicodeveloper/laravel-identify) 4 | ![](https://img.shields.io/badge/unicodeveloper-approved-brightgreen.svg) 5 | [![License](https://poser.pugx.org/unicodeveloper/laravel-identify/license.svg)](LICENSE.md) 6 | [![Build Status](https://img.shields.io/travis/unicodeveloper/laravel-identify.svg)](https://travis-ci.org/unicodeveloper/laravel-identify) 7 | [![Coveralls](https://img.shields.io/coveralls/unicodeveloper/laravel-identify/master.svg)](https://coveralls.io/github/unicodeveloper/laravel-identify?branch=master) 8 | [![Quality Score](https://img.shields.io/scrutinizer/g/unicodeveloper/laravel-identify.svg?style=flat-square)](https://scrutinizer-ci.com/g/unicodeveloper/laravel-identify) 9 | [![Total Downloads](https://img.shields.io/packagist/dt/unicodeveloper/laravel-identify.svg?style=flat-square)](https://packagist.org/packages/unicodeveloper/laravel-identify) 10 | 11 | > Laravel 5 Package to identify a User's Browser, Operating System, Language and Device 12 | 13 | ## Installation 14 | 15 | [PHP](https://php.net) 7.1+ or [HHVM](http://hhvm.com) 3.3+, and [Composer](https://getcomposer.org) are required. 16 | 17 | To get the latest version of Laravel Identify, simply add the following line to the require block of your `composer.json` file. 18 | 19 | ``` 20 | "unicodeveloper/laravel-identify": "1.7.*" 21 | ``` 22 | 23 | You'll then need to run `composer install` or `composer update` to download it and have the autoloader updated. 24 | 25 | - If you're on Laravel 5.5 or above, that's all you need to do! Check out the usage examples below. 26 | - If you're on Laravel < 5.5, you'll need to register the service provider once the package is installed. Open up `config/app.php` and add the following to the `providers` array: 27 | 28 | * `Unicodeveloper\Identify\IdentifyServiceProvider::class` 29 | 30 | Also, register the Facade like so: 31 | 32 | ```php 33 | 'aliases' => [ 34 | ... 35 | 'Identify' => Unicodeveloper\Identify\Facades\IdentifyFacade::class, 36 | ... 37 | ] 38 | ``` 39 | 40 | ## Configuration 41 | 42 | To get started, you'll need to publish all vendor assets: 43 | 44 | ```bash 45 | $ php artisan vendor:publish --provider="Unicodeveloper\Identify\IdentifyServiceProvider" 46 | ``` 47 | ## Browser Detection 48 | 49 | The browser method allows you to detect a user's browser and version. 50 | 51 | ### Browsers Detected 52 | 53 | * Vivaldi 54 | * Opera 55 | * Opera Mini 56 | * WebTV 57 | * Internet Explorer 58 | * Pocket Internet Explorer 59 | * Microsoft Edge 60 | * Konqueror 61 | * iCab 62 | * OmniWeb 63 | * Firebird 64 | * Firefox 65 | * Iceweasel 66 | * Shiretoko 67 | * Mozilla 68 | * Amaya 69 | * Lynx 70 | * Safari 71 | * Chrome 72 | * Navigator 73 | * GoogleBot 74 | * Yahoo! Slurp 75 | * W3C Validator 76 | * BlackBerry 77 | * IceCat 78 | * Nokia S60 OSS Browser 79 | * Nokia Browser 80 | * MSN Browser 81 | * MSN Bot 82 | * Netscape Navigator 83 | * Galeon 84 | * NetPositive 85 | * Phoenix 86 | * SeaMonkey 87 | * Yandex Browser 88 | 89 | ### Usage 90 | 91 | ```php 92 | /** 93 | * Gets the version of the user's browser 94 | * @return string 95 | */ 96 | Identify::browser()->getVersion() 97 | 98 | /** 99 | * Gets the name of the user's browser 100 | * @return string 101 | */ 102 | Identify::browser()->getName() 103 | ``` 104 | ## OS Detection 105 | 106 | The os method allows you to detect a user's operating system and version. 107 | 108 | ### OS Detected 109 | 110 | * Windows 111 | * Windows Phone 112 | * OS X 113 | * iOS 114 | * Android 115 | * Chrome OS 116 | * Linux 117 | * SymbOS 118 | * Nokia 119 | * BlackBerry 120 | * FreeBSD 121 | * OpenBSD 122 | * NetBSD 123 | * OpenSolaris 124 | * SunOS 125 | * OS2 126 | * BeOS 127 | 128 | ### Usage 129 | 130 | ```php 131 | /** 132 | * Gets the version of the user's Operating System 133 | * @return string 134 | */ 135 | Identify::os()->getVersion() 136 | 137 | /** 138 | * Gets the name of the user's Operating System 139 | * @return string 140 | */ 141 | Identify::os()->getName() 142 | ``` 143 | 144 | ## Device Detection 145 | 146 | The device method allows you to detect a user's device. 147 | 148 | ### Device Detected 149 | 150 | * iPad 151 | * iPhone 152 | * Windows Phone 153 | 154 | ### Usage 155 | 156 | ```php 157 | /** 158 | * Gets the name of the user's device 159 | * @return string 160 | */ 161 | Identify::device()->getName() 162 | ``` 163 | 164 | ## Language Detection 165 | 166 | The language method allows you to detect a user's language. 167 | 168 | ### Usage 169 | 170 | ```php 171 | /** 172 | * Gets the language that the user's browser contents are displayed in 173 | * @return string 174 | */ 175 | Identify::lang()->getLanguage() 176 | ``` 177 | 178 | 179 | ## Contributing 180 | 181 | Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities. 182 | 183 | 184 | ## How can I thank you? 185 | 186 | Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word! 187 | 188 | Don't forget to [follow me on twitter](https://twitter.com/unicodeveloper)! 189 | 190 | Thanks! 191 | Prosper Otemuyiwa. 192 | 193 | ## License 194 | 195 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 196 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unicodeveloper/laravel-identify", 3 | "description": "A Laravel 5 Package Provider to Identify/detect a user's browser, device, operating system and Language", 4 | "keywords": ["github", "laravel","Open Source","Evangelist", "Detect", "Identify", "Browser", "Operating System", "Language"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "unicodeveloper", 9 | "email": "prosperotemuyiwa@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": ">=7.1.3", 14 | "illuminate/support": "~5.7.0|~5.8.0", 15 | "sinergi/browser-detector": "6.1.*" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "~6.0.0", 19 | "mockery/mockery": "0.9.*", 20 | "scrutinizer/ocular": "~1.1", 21 | "satooshi/php-coveralls": "^0.7.0" 22 | }, 23 | "autoload": { 24 | "psr-4": { 25 | "Unicodeveloper\\Identify\\": "src/" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "Unicodeveloper\\Identify\\Test\\": "tests" 31 | } 32 | }, 33 | "scripts": { 34 | "test": "vendor/bin/phpunit" 35 | }, 36 | "extra": { 37 | "laravel": { 38 | "providers": [ 39 | "Unicodeveloper\\Identify\\IdentifyServiceProvider" 40 | ], 41 | "aliases": { 42 | "Identify": "Unicodeveloper\\Identify\\Facades\\IdentifyFacade" 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | tests 15 | 16 | 17 | 18 | 19 | src/ 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Exceptions/IdentifyException.php: -------------------------------------------------------------------------------- 1 | os = new Os(); 39 | $this->device = new Device(); 40 | $this->browser = new Browser(); 41 | $this->language = new Language(); 42 | } 43 | 44 | /** 45 | * Get all the methods applicable to Os detection 46 | * e.g getName(), getVersion() 47 | * @return \Sinergi\BrowserDetector\Os 48 | */ 49 | public function os() : Os 50 | { 51 | return $this->os; 52 | } 53 | 54 | /** 55 | * Get all the methods applicable to Device detection 56 | * e.g getName() 57 | * @return \Sinergi\BrowserDetector\Device 58 | */ 59 | public function device() : Device 60 | { 61 | return $this->device; 62 | } 63 | 64 | /** 65 | * Get all the methods applicable to Browser detection 66 | * e.g getName(), getVersion() 67 | * @return \Sinergi\BrowserDetector\Browser 68 | */ 69 | public function browser() : Browser 70 | { 71 | return $this->browser; 72 | } 73 | 74 | /** 75 | * Get all the methods applicable to Language detection 76 | * e.g getLanguage() 77 | * @return \Sinergi\BrowserDetector\Language 78 | */ 79 | public function lang() : Language 80 | { 81 | return $this->language; 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /src/IdentifyServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->bind('laravel-identify', function() { 24 | 25 | return new Identify; 26 | 27 | }); 28 | } 29 | 30 | /** 31 | * Get the services provided by the provider 32 | * @return array 33 | */ 34 | public function provides() : array 35 | { 36 | return ['laravel-identify']; 37 | } 38 | } -------------------------------------------------------------------------------- /tests/IdentifyServiceProviderTest.php: -------------------------------------------------------------------------------- 1 | mockApp = m::mock('\Illuminate\Contracts\Foundation\Application'); 26 | $this->provider = new IdentifyServiceProvider($this->mockApp); 27 | } 28 | 29 | /** 30 | * Test that it registers the correct service name with Identity 31 | */ 32 | public function testRegister() 33 | { 34 | $this->mockApp->shouldReceive('bind') 35 | ->once() 36 | ->andReturnUsing(function($name, $closure) { 37 | $this->assertEquals('laravel-identify', $name); 38 | $this->assertInstanceOf(Identify::class, $closure()); 39 | }); 40 | 41 | $this->provider->register(); 42 | } 43 | 44 | /** 45 | * Test that it provides the correct service name 46 | */ 47 | public function testProvides() 48 | { 49 | $expected = ['laravel-identify']; 50 | $actual = $this->provider->provides(); 51 | 52 | $this->assertEquals($expected, $actual); 53 | } 54 | } -------------------------------------------------------------------------------- /tests/IdentifyTest.php: -------------------------------------------------------------------------------- 1 | identify = new Identify(); 22 | } 23 | 24 | /** 25 | * Test if Identify can be constructed 26 | * 27 | */ 28 | public function testIdentifyCanBeConstructed() 29 | { 30 | $this->assertInstanceOf(Identify::class, $this->identify); 31 | } 32 | 33 | /** 34 | * Test if Os is constructed on Identify Object created 35 | * 36 | */ 37 | public function testOSIsInitializedOnIdentifyConstruction() 38 | { 39 | $this->assertInstanceOf(Os::class, $this->identify->os()); 40 | } 41 | 42 | /** 43 | * Test if Device is constructed on Identify Object created 44 | * 45 | */ 46 | public function testDeviceIsInitializedOnIdentifyConstruction() 47 | { 48 | $this->assertInstanceOf(Device::class, $this->identify->device()); 49 | } 50 | 51 | /** 52 | * Test if Os is constructed on Identify Object created 53 | * 54 | */ 55 | public function testBrowserIsInitializedOnIdentifyConstruction() 56 | { 57 | $this->assertInstanceOf(Browser::class, $this->identify->browser()); 58 | } 59 | 60 | /** 61 | * Test if Language is constructed on Identify Object created 62 | * 63 | */ 64 | public function testLanguageIsInitializedOnIdentifyConstruction() 65 | { 66 | $this->assertInstanceOf(Language::class, $this->identify->lang()); 67 | } 68 | } 69 | --------------------------------------------------------------------------------