Api
3 years ago
Integrations
3 years ago
StorageDriver
4 years ago
Url
3 years ago
data
6 years ago
Api.php
3 years ago
Backlog.php
4 years ago
BacklogReplayTimeoutException.php
4 years ago
ChallengeProcessingException.php
4 years ago
ChallengeVerificationException.php
4 years ago
ConfigFetcherException.php
4 years ago
Crypto.php
3 years ago
Device.php
6 years ago
DeviceType.php
6 years ago
ElementRevision.php
3 years ago
EmptyConfigException.php
6 years ago
FileHandle.php
5 years ago
Filesystem.php
4 years ago
HealthStatus.php
5 years ago
IntegrationUrl.php
6 years ago
NitroPack.php
3 years ago
NoConfigException.php
5 years ago
Pagecache.php
2 years ago
PurgeType.php
3 years ago
ServiceDownException.php
5 years ago
StorageException.php
6 years ago
VariationCookieException.php
5 years ago
WebhookException.php
5 years ago
Website.php
6 years ago
Device.php
65 lines
| 1 | <?php |
| 2 | namespace NitroPack\SDK; |
| 3 | |
| 4 | class Device { |
| 5 | private $userAgent; |
| 6 | |
| 7 | public static function getKnownTypes() { |
| 8 | return array(DeviceType::MOBILE, DeviceType::TABLET, DeviceType::DESKTOP); |
| 9 | } |
| 10 | |
| 11 | public function __construct($userAgent = "") { |
| 12 | $this->userAgent = $userAgent; |
| 13 | } |
| 14 | |
| 15 | public function getUserAgent() { |
| 16 | return $this->userAgent; |
| 17 | } |
| 18 | |
| 19 | public function isDesktop() { |
| 20 | return !($this->isMobile() && $this->isTablet()); |
| 21 | } |
| 22 | |
| 23 | public function isMobile() { |
| 24 | if (empty($this->userAgent)) return false; |
| 25 | |
| 26 | $mobile_agents = array('iPod','iPhone','MobileSafari','webOS','BlackBerry','windows phone','symbian','vodafone','opera mini','windows ce','smartphone','palm','midp'); |
| 27 | |
| 28 | foreach($mobile_agents as $mobile_agent){ |
| 29 | if(stripos($this->userAgent, $mobile_agent)) { |
| 30 | return true; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | if(stripos($this->userAgent, "Android") && stripos($this->userAgent, "mobile")) { |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | public function isTablet() { |
| 42 | if (empty($this->userAgent)) return false; |
| 43 | |
| 44 | $tablet_agents = array('iPad','RIM Tablet','hp-tablet','Kindle Fire','Android'); |
| 45 | |
| 46 | foreach($tablet_agents as $tablet_agent){ |
| 47 | if(stripos($this->userAgent, $tablet_agent)) { |
| 48 | return true; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if(stripos($this->userAgent, "Android") && stripos($this->userAgent, "mobile")) { |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | public function getType() { |
| 60 | if ($this->isMobile()) return DeviceType::MOBILE; |
| 61 | if ($this->isTablet()) return DeviceType::TABLET; |
| 62 | return DeviceType::DESKTOP; |
| 63 | } |
| 64 | } |
| 65 |