Skip to content

Commit

Permalink
Add isPhone method, fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed Oct 16, 2015
1 parent f74033f commit 6b9a79a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 6b9a79a

Please sign in to comment.