PHP code example of mimmi20 / wurfl

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

    

mimmi20 / wurfl example snippets


/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 *
 * change this to pass to your project settings
 */
chdir(dirname(__DIR__));
sourcesDir . '/storage/cache';

// 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
 *
 * It is recommended to use the defined class constants instead of their
 * string values:
 *
 * \Wurfl\Configuration\Config::MATCH_MODE_PERFORMANCE
 * \Wurfl\Configuration\Config::MATCH_MODE_ACCURACY
 */
$wurflConfig->matchMode(\Wurfl\Configuration\Config::MATCH_MODE_PERFORMANCE);

// Setup WURFL Persistence
$wurflConfig->persistence(
    'file',
    array(\Wurfl\Configuration\Config::DIR => $persistenceDir)
);

// Setup Caching
$wurflConfig->cache(
    'file',
    array(
        \Wurfl\Configuration\Config::DIR        => $cacheDir,
        \Wurfl\Configuration\Config::EXPIRATION => 36000
    )
);

// Create the cache instance from the configuration
$cacheStorage = Storage\Factory::create($wurflConfig->cache);

// Create the persistent cache instance from the configuration
$persistenceStorage = Storage\Factory::create($wurflConfig->persistence);

// Create a WURFL Manager from the WURFL Configuration
$wurflManager = new \Wurfl\Manager($wurflConfig, $persistenceStorage, $cacheStorage);

$wurflManager = \Wurfl\Manager::factory($wurflConfig);

$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
 *
 * It is recommended to use the defined class constants instead of their
 * string values:
 *
 * \Wurfl\Configuration\Config::MATCH_MODE_PERFORMANCE
 * \Wurfl\Configuration\Config::MATCH_MODE_ACCURACY
 */
$wurflConfig->matchMode(\Wurfl\Configuration\Config::MATCH_MODE_PERFORMANCE);

// Setup WURFL Persistence
$wurflConfig->persistence(
    'file',
    array(\Wurfl\Configuration\Config::DIR => $persistenceDir)
);

// Setup Caching
$wurflConfig->cache(
    'file',
    array(
        \Wurfl\Configuration\Config::DIR        => $cacheDir,
        \Wurfl\Configuration\Config::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\CustomDeviceInterface */
$device = $wurflManager->getDeviceForHttpRequest($_SERVER);

/* @var $root \Wurfl\Device\ModelDeviceInterface */
$root = $device->getRootDevice();

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

$wurflConfig->allowReload(true);