定制 acasademont/wurfl 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

acasademont/wurfl

Composer 安装命令:

composer require acasademont/wurfl

包简介

WURFL Library port to composer

关键字:

README 文档

README

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.

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

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/

Getting Started

Download a release archive from wurfl site and extract it to a directory suitable for your application.

To start using the API you need to set some configuration options.

IMPORTANT: The WURFL API is closely tied to the WURFL.XML file. New versions of the WURFL.XML are 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.

For the impatient ones

Please look at the sample of the configuration files in examples/demo/ directory.

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

require_once $wurflDir.'/Application.php';

$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 ('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();

Now you can use some of the WURFL_WURFLManager class methods;

$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)

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

  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:

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 ('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));

Using the WURFL PHP API

Getting the device

You have four methods for retrieving a device:

  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.

  2. getDeviceForHttpRequest($_SERVER) Most of the time you will use this method, and the API will create the WURFL_Request_GenericRequest object for you.

  3. getDeviceForUserAgent(string $userAgent) Used to query the API for a given userAgent string.

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

Usage example:

$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:

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

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

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

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

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

Useful Methods

The root WURFL device object has some useful functions:

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

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:

$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

acasademont/wurfl 适用场景与选型建议

acasademont/wurfl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.13k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Wurfl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 acasademont/wurfl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 acasademont/wurfl 我们能提供哪些服务?
定制开发 / 二次开发

基于 acasademont/wurfl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16.13k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GNU
  • 更新时间: 2015-05-07