Skip to content

Added mobile detection #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ The language method allows you to detect a user's language.
Identify::lang()->getLanguage()
```

## Mobile Detection

The mobile method allows you to detect if user is on mobile.

### Usage

```php
/**
* Returns true if any type of mobile device detected, including special ones
* @return boolean
*/
Identify::mobile()->isMobile()

/**
* Return true if any type of tablet device is detected.
* @return boolean
*/
Identify::mobile()->isTablet()
```

## Contributing

Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"require": {
"php": ">=7.1.3",
"illuminate/support": "~5.7.0|~5.8.0",
"sinergi/browser-detector": "6.1.*"
"sinergi/browser-detector": "6.1.*",
"mobiledetect/mobiledetectlib": "^2.8"
},
"require-dev": {
"require-dev": {
"phpunit/phpunit": "~6.0.0",
"mockery/mockery": "0.9.*",
"scrutinizer/ocular": "~1.1",
Expand Down
19 changes: 18 additions & 1 deletion src/Identify.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Identify {
*/
protected $language;

/**
* Store the mobile object
* @var object
*/
protected $mobile;

/**
* Create an Instance of Browser and Os
*/
Expand All @@ -39,6 +45,7 @@ public function __construct()
$this->device = new Device();
$this->browser = new Browser();
$this->language = new Language();
$this->mobile = new \Mobile_Detect();
}

/**
Expand Down Expand Up @@ -81,4 +88,14 @@ public function lang() : Language
return $this->language;
}

}
/**
* Get all the methods applicable to Mobile detection
* e.g isMobile()
* @return \Mobile_Detect
*/
public function mobile() : \Mobile_Detect
{
return $this->mobile;
}

}
9 changes: 9 additions & 0 deletions tests/IdentifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,13 @@ public function testLanguageIsInitializedOnIdentifyConstruction()
{
$this->assertInstanceOf(Language::class, $this->identify->lang());
}

/**
* Test if MobileDetect is constructed on Identify Object created
*
*/
public function testMobileIsInitializedOnIdentifyConstruction()
{
$this->assertInstanceOf(\Mobile_Detect::class, $this->identify->mobile());
}
}