A powerful Symfony bundle for user-agent analysis. It provides accurate detection of operating systems (Windows, MacOS, Linux, iOS, Android...), browsers (Chrome, Firefox, Safari...), and device types (Desktop, Mobile, Tablet, TV...). Supports specific version detection and includes advanced handling of special cases like WebViews and compatibility modes.
Operating System Detection
Browser Detection
Device Detection
Advanced Features
composer require eprofos/user-agent-analyzer
If you're not using Symfony Flex, add the bundle to your config/bundles.php:
return [
// ...
Eprofos\UserAgentAnalyzerBundle\EprofosUserAgentAnalyzerBundle::class => ['all' => true],
];
use Eprofos\UserAgentAnalyzerBundle\Service\UserAgentAnalyzer;
class YourController
{
public function someAction(UserAgentAnalyzer $analyzer)
{
$result = $analyzer->analyzeCurrentRequest();
// Access the results
$osName = $result->getOsName(); // e.g., "Windows"
$osVersion = $result->getOsVersion(); // e.g., 10.0
$browserName = $result->getBrowserName(); // e.g., "Chrome"
$deviceType = $result->getDeviceType(); // e.g., "desktop"
// Check device type
$isMobile = $result->isMobile(); // true if device is mobile
$isDesktop = $result->isDesktop(); // true if device is desktop
$isTablet = $result->isTablet(); // true if device is tablet
// Get all information as array
$allInfo = $result->toArray();
}
}
use Eprofos\UserAgentAnalyzerBundle\Service\UserAgentAnalyzer;
class YourController
{
public function someAction(
UserAgentAnalyzer $analyzer,
Request $request
) {
{
// Analyze current request with touch support detection
$result = $analyzer->analyzeCurrentRequest(true);
// Or analyze specific user agent with touch support
$userAgent = $request->headers->get('User-Agent');
$result = $analyzer->analyze($userAgent, true);
// Check for specific browser features
$isWebView = $result->isBrowserAndroidWebview() || $result->isBrowserIosWebview();
$isDesktopMode = $result->isBrowserDesktopMode();
$is64Bit = $result->is64BitsMode();
}
}
The bundle provides several Twig functions for easy device and OS detection in your templates:
{# Device Type Detection #}
{% if is_mobile() %}
{# Mobile-specific content #}
{% endif %}
{% if is_desktop() %}
{# Desktop-specific content #}
{% endif %}
{% if is_tablet() %}
{# Tablet-specific content #}
{% endif %}
{# Operating System Detection #}
{% if is_android() %}
{# Android-specific content #}
{% endif %}
{% if is_windows() %}
{# Windows-specific content #}
{% endif %}
{% if is_linux() %}
{# Linux-specific content #}
{% endif %}
{% if is_ios() %}
{# iOS-specific content #}
{% endif %}
{% if is_macos() %}
{# macOS-specific content #}
{% endif %}
All Twig functions automatically analyze the current request's User-Agent string and return a boolean value indicating whether the condition is met.
getOsType(): Get OS type (desktop, mobile, etc.)getOsFamily(): Get OS family (windows, macintosh, etc.)getOsName(): Get OS namegetOsVersion(): Get OS versiongetOsTitle(): Get formatted OS name with versiongetBrowserName(): Get browser namegetBrowserVersion(): Get browser versiongetBrowserTitle(): Get formatted browser name with versiongetBrowserChromiumVersion(): Get Chromium version if applicablegetBrowserGeckoVersion(): Get Gecko version if applicablegetBrowserWebkitVersion(): Get WebKit version if applicableisBrowserChromeOriginal(): Check if browser is original ChromeisBrowserFirefoxOriginal(): Check if browser is original FirefoxisBrowserSafariOriginal(): Check if browser is original SafarigetDeviceType(): Get device typeisMobile(): Check if device is mobileisDesktop(): Check if device is desktopisTablet(): Check if device is tabletisBrowserAndroidWebview(): Check if Android WebViewisBrowserIosWebview(): Check if iOS WebViewisBrowserDesktopMode(): Check if desktop modeis64BitsMode(): Check if 64-bit modecomposer test
# Run PHP CS Fixer
composer cs-fix
# Run PHPStan
composer phpstan
# Run all quality tools
composer analyze
Feel free to contribute to this bundle by submitting issues and pull requests.
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)This bundle is released under the MIT License. See the bundled LICENSE file for details.
Developed by Eprofos.
How can I help you explore Laravel packages today?