PHP code example of acsiomatic / device-detector-bundle

1. Go to this page and download the library: Download acsiomatic/device-detector-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

acsiomatic / device-detector-bundle example snippets


use DeviceDetector\DeviceDetector;
use Symfony\Component\HttpFoundation\Response;

class MyController
{
    public function index(DeviceDetector $device): Response
    {
        if ($device->isSmartphone()) {
            // ...
        }
    }
}

use Symfony\Component\HttpFoundation\Response;

class MyController
{
    #[Route('/page', condition: "service('device').isSmartphone()")]
    public function index(): Response
    {
        // this endpoint is available only for smartphone devices
    }
}