diff --git a/README.md b/README.md index cddc7b2..7963ec6 100644 --- a/README.md +++ b/README.md @@ -129,12 +129,20 @@ $browser = $agent->browser(); ### Desktop detection -Check if the user is a desktop. +Check if the user is using a desktop device. ```php $agent->isDesktop(); ``` +### Phone detection + +Check if the user is using a phone device. + +```php +$agent->isPhone(); +``` + *This checks if a user is not a mobile device, tablet or robot.* ### Robot detection diff --git a/src/Agent.php b/src/Agent.php index 2e38f90..dc7094e 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -224,6 +224,18 @@ public function isDesktop($userAgent = null, $httpHeaders = null) return (! $this->isMobile() && ! $this->isTablet() && ! $this->isRobot()); } + /** + * Check if the device is a mobile phone. + * + * @param string $userAgent deprecated + * @param array $httpHeaders deprecated + * @return bool + */ + public function isPhone($userAgent = null, $httpHeaders = null) + { + return ($this->isMobile() && ! $this->isTablet()); + } + /** * Get the robot name. * diff --git a/tests/AgentTest.php b/tests/AgentTest.php index e09c59d..f7ec054 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -177,18 +177,21 @@ public function testDesktop() { $agent->setUserAgent($ua); $this->assertTrue($agent->isDesktop(), $ua); + $this->assertFalse($agent->isMobile(), $ua); } foreach($this->robots as $ua => $robot) { $agent->setUserAgent($ua); $this->assertFalse($agent->isDesktop(), $ua); + $this->assertFalse($agent->isMobile(), $ua); } foreach($this->devices as $ua => $device) { $agent->setUserAgent($ua); $this->assertFalse($agent->isDesktop(), $ua); + $this->assertTrue($agent->isMobile(), $ua); } }