PHP code example of wurfl / wurfl-api

1. Go to this page and download the library: Download wurfl/wurfl-api 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/ */

    

wurfl / wurfl-api example snippets


$wurflDir = dirname(__FILE__) . '/../../../WURFL';
$resourcesDir = dirname(__FILE__) . '/../../resources';

eate WURFL Configuration
$wurflConfig = new WURFL_Configuration_InMemoryConfig();

// Set location of the WURFL File
$wurflConfig->wurflFile($resourcesDir.'/wurfl.zip');

// Set the match mode for the API ('performance' or 'accuracy')
$wurflConfig->matchMode('performance');

// Setup WURFL Persistence
$wurflConfig->persistence('file', array('dir' => $persistenceDir));

// Setup Caching
$wurflConfig->cache('file', array('dir' => $cacheDir, 'expiration' => 36000));

// Create a WURFL Manager Factory from the WURFL Configuration
$wurflManagerFactory = new WURFL_WURFLManagerFactory($wurflConfig);

// Create a WURFL Manager
/* @var $wurflManager WURFL_WURFLManager */
$wurflManager = $wurflManagerFactory->create();

$device = $wurflManager->getDeviceForHttpRequest($_SERVER);
$device->getCapability("is_wireless_device");
$device->getVirtualCapability("is_smartphone");

// Create WURFL Configuration
$wurflConfig = new WURFL_Configuration_InMemoryConfig();
// Set location of the WURFL File
$wurflConfig->wurflFile($resourcesDir.'/wurfl.zip');
// Set the match mode for the API ('performance' or 'accuracy')
$wurflConfig->matchMode('performance');
// Setup WURFL Persistence
$wurflConfig->persistence('file', array('dir' => $persistenceDir));
// Setup Caching
$wurflConfig->cache('file', array('dir' => $cacheDir, 'expiration' => 36000));

$device = $wurflManager->getDeviceForHttpRequest($_SERVER);

$deviceID = $device->id;
$fallBack = $device->fallBack;

$value = $device->getCapability("is_tablet");
$allCaps = $device->getAllCapabilities();

$value = $device->getVirtualCapability("is_smartphone");
$allVCaps = $device->getAllVirtualCapabilities();

/* @var $device WURFL_CustomDevice */
$device = $wurflManager->getDeviceForHttpRequest($_SERVER);

/* @var $root WURFL_Xml_ModelDevice */
$root = $device->getRootDevice();

$group_names = $root->getGroupNames();
$cap_names = $root->getCapNames();
$defined = $root->isCapabilityDefined("foobar");

$wurflConfig->allowReload(true);