2017 © Pedro Peláez
 

library wurfl

the Wurfl PHP Library for PHP 5.3+

image

mimmi20/wurfl

the Wurfl PHP Library for PHP 5.3+

  • Sunday, January 8, 2017
  • by mimmi20
  • Repository
  • 5 Watchers
  • 13 Stars
  • 26,426 Installations
  • PHP
  • 2 Dependents
  • 1 Suggesters
  • 4 Forks
  • 0 Open issues
  • 17 Versions
  • 4 % Grown

The README.md

Wurfl

an clone of the official Wurfl PHP library updated for PHP 5.3, (*1)

Build Status Scrutinizer Quality Score Code Coverage, (*2)

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub, (*3)

Important changes

These changes are made: - added Wurfl namespace, removed the part "WURFL" from the filenames - merged the \Wurfl\Service and \Wurfl\ManagerFactory into \Wurl\Manager - Parts of the original Wurfl Package were extracted to their own repositories, these are installed via composer - the Xml Configuration class is replaced with FileConfig class, who is also able to read config files in ini/yaml format, (*4)

# the official WURFL PHP API

  • http://www.scientiamobile.com/
  • http://wurfl.sourceforge.com/

LICENSE

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*5)

Please refer to the COPYING file distributed with this package for the complete text of the applicable GNU Affero General Public License., (*6)

If you are not able to comply with the terms of the AGPL license, commercial licenses are available from ScientiaMobile, Inc at http://www.ScientiaMobile.com/, (*7)

Getting Started

Download a release archive from wurfl site and extract it to a directory suitable for your application., (*8)

To start using the API you need to set some configuration options., (*9)

IMPORTANT: The WURFL API is closely tied to the WURFL.XML file. New versions of the WURFL.XML may be compatible with old versions of the API by nature, but the reverse is NOT true. Old versions of the WURFL.XML are NOT guarenteed to be compatible with new versions of the API. Let's restate that: This API is NOT compatible with old versions of the WURFL.XML. The oldest copy of WURFL that can be used with this API is included in this distribution., (*10)

/**
 * 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__));
require 'vendor/autoload.php';

/*
 * relative to the root dir
 * -> $resourcesDir = <Project Root>/resources
 */
$resourcesDir   = 'resources';
$persistenceDir = $resourcesDir . '/storage/persistence';
$cacheDir       = $resourcesDir . '/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);

If you dont want to build these three objects by yourself, you may use the factory method., (*11)

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

Now you can use some of the \Wurfl\Manager class methods;, (*12)

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

Create a configuration object

  1. Set the paths to the location of the main WURFL file (you can use zip files if you have the zip extension enabled), (*13)

  2. Configure the Persistence provider by specifying the provider and the extra parameters needed to initialize the provider. The API supports the following mechanisms:, (*14)

    • Memcache (http://uk2.php.net/memcache)
    • APC (Alternative PHP Cache http://www.php.net/apc)
    • Memory
    • File

    Additional to the official providers the following connectors are added:, (*15)

    • Zend Cache
  3. Configure the Cache provider by specifying the provider and the extra parameters needed to initialize the provider. The API supports the following caching mechanisms:, (*16)

    • Memcache (http://uk2.php.net/memcache)
    • APC (Alternative PHP Cache http://www.php.net/apc)
    • File
    • Null (no caching)

    Additional to the official providers the following connectors are added:, (*17)

    • Zend Cache

Example Configuration

// 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
    )
);

Using the WURFL PHP API

Getting the device

You have four methods for retrieving a device:, (*18)

  1. getDeviceForRequest(\Wurfl\Request\GenericRequest $request) where a \Wurfl\Request\GenericRequest is an object which encapsulates userAgent, ua-profile, support for xhtml of the device., (*19)

  2. getDeviceForHttpRequest($_SERVER) Most of the time you will use this method, and the API will create the the \Wurfl\Request\GenericRequest object for you, (*20)

  3. getDeviceForUserAgent(string $userAgent) Used to query the API for a given User Agent string, (*21)

  4. getDevice(string $deviceID) Gets the device by its device ID (ex: apple_iphone_ver1), (*22)

Usage example:, (*23)

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

Getting the device properties and its capabilities

The properties Device ID and Fall Back Device ID are properties of the device:, (*24)

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

To get the value of a capability, use getCapability():, (*25)

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

To get the value of a virtual capability, use getVirtualCapability():, (*26)

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

Useful Methods

The root WURFL device object has some useful functions:, (*27)

/* @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");

WURFL Reloader

WURFL can update the persistence data automatically without any configuration by checking the modification time of the WURFL file. To enable, set allow-reload to true in the config:, (*28)

$wurflConfig->allowReload(true);

If you have any questions, please take a look at the documentation on http://wurfl.sourceforge.net, and/or the ScientiaMobile Support Forum at http://www.scientiamobile.com/forum, (*29)

The Versions

24/04 2016
24/04 2016
12/03 2016

1.7.0.0-beta2

1.7.0.0-beta2 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3+

  Sources   Download

AGPLv3

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

17/08 2015
19/05 2015

1.6.0.0

1.6.0.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

31/01 2015

1.5.3.0

1.5.3.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

04/10 2014

1.3.0

1.3.0.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

02/05 2014

1.2.1

1.2.1.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

09/04 2014

1.2.0

1.2.0.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

26/01 2014

1.1.1

1.1.1.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

03/12 2013

1.0.1

1.0.1.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent

02/12 2013

1.0.0

1.0.0.0 https://github.com/mimmi20/Wurfl

the Wurfl PHP Library for PHP 5.3

  Sources   Download

LGPL-2.1

The Requires

 

The Development Requires

parser http wurfl browser user agent user-agent