Created persistence for device long URLs

This commit is contained in:
Alejandro Celaya
2023-01-21 10:12:52 +01:00
parent 5f2f179581
commit 12150f775d
14 changed files with 209 additions and 38 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Shlinkio\Shlink\Core\Model;
use Detection\MobileDetect;
enum DeviceType: string
{
case ANDROID = 'android';
case IOS = 'ios';
case DESKTOP = 'desktop';
public static function matchFromUserAgent(string $userAgent): ?self
{
$detect = new MobileDetect(null, $userAgent); // @phpstan-ignore-line
return match (true) {
// $detect->is('iOS') && $detect->isTablet() => self::IOS, // TODO To detect iPad only
// $detect->is('iOS') && ! $detect->isTablet() => self::IOS, // TODO To detect iPhone only
// $detect->is('androidOS') && $detect->isTablet() => self::ANDROID, // TODO To detect Android tablets
// $detect->is('androidOS') && ! $detect->isTablet() => self::ANDROID, // TODO To detect Android phones
$detect->is('iOS') => self::IOS, // Detects both iPhone and iPad
$detect->is('androidOS') => self::ANDROID, // Detects both android phones and android tablets
! $detect->isMobile() && ! $detect->isTablet() => self::DESKTOP,
default => null,
};
}
}