Zend Framework: Zend_Http_UserAgent (was Zend_Browser) Component Proposal
| Proposed Component Name | Zend_Http_UserAgent (was Zend_Browser) |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Http_UserAgent (was Zend_Browser) |
| Proposers | Raphaël Carles |
| Zend Liaison | |
| Revision | 1.0 - 03 August 2010: Initial Draft. (wiki revision: 12) |
Table of Contents
- 1. Overview
- 2. References
- 3. Component Requirements, Constraints, and Acceptance Criteria
- 4. Dependencies on Other Framework Components
- 5. Theory of Operation
- 6. Milestones / Tasks
- 7. Class Index
- 8. Use Cases
- Standard usage
- Forced User Agent (for testing)
- Changing the identification sequence
- Changing the persistent storage
- To add or change a matcher
- To define a new adapter to collect browser/device features
- 9. Class Skeletons
1. Overview
This proposition covers several classes dedicated to the client browser/device detection and the available associated features and capabilities.
Its aim is to provide an interface to devices identification libraries like WURFL or DeviceAtlas and ease browsers differences handling, including mobile browsers.
This normalization of client environment detection can ease the management of multi-support development.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will allow quick detection of browsers, using per-session storage of last identification data
- This component will ease the use of external device identification libraries
- This component will be lightweight by using singleton pattern
- This component will provide an easy way to include new browsers types to detect.
- This component will not provide content adaptation/content replacement mechanisms or helpers
4. Dependencies on Other Framework Components
- Zend_Session (optional)
5. Theory of Operation
The UserAgent component should be seen as an information provider to Zend Framework applications at any level (helpers, controllers...)
Detection relies on declared or forced user agent information from server vars. It allows to have a standard behavior in the case that user agent string is present, a default one otherwise, and a forced mode where user agent is given at call time.
The identification class has a declared list of browsers types, ordered by priority.
Priorities can be changed to reflect application orientation (eg. a mobile-oriented website should have a faster identification of mobile devices than desktop ones).
New browser types can be developed and added to the priority list (or to extend an existing one), allowing wider recognition (probes, text browsers, ...) for the application that uses it.
The identification function is not called directly, although this is also possible.
All calls should be done to the getInstance method to execute the full identification process only one time per-request, or if session is activated, one time per-session and user agent.
After a quick detection of browser type, Zend_UserAgent can populate features by two ways :
- by responding directly to features checks (eg. return false to every request for a text browser, return true to every request for a desktop browser)
- by delegating to a Zend_UserAgent_Features_Adapter that will retrieve features.
The result is then stored as mentioned to bypass identification at next call (unless another user agent is forced).
6. Milestones / Tasks
Component already done for specific developments without ZF.
- Milestone 1: refactoring of existing code and adpatations to ZF design standards
- Milestone 2: Working prototype checked into the incubator supporting use cases #1, #2, ...
- Milestone 3: Working prototype checked into the incubator supporting use cases #3 and #4.
- Milestone 4: Unit tests exist, work, and are checked into SVN.
- Milestone 5: Initial documentation exists.
7. Class Index
- Zend_UserAgent
- Zend_UserAgent_AbstractUserAgent
- Zend_UserAgent_Mobile
- Zend_UserAgent_Tablet
- Zend_UserAgent_Desktop (by default)
- Zend_UserAgent_Bot
- Zend_UserAgent_Text
- Zend_UserAgent_Features_Adapter
- Zend_UserAgent_Features_Adapter_WurflPhpApi (the first adapter to be provided)
- Zend_UserAgent_Features_Adapter_Wurfl
- Zend_UserAgent_Features_Adapter_TeraWurfl
- Zend_UserAgent_Features_Adapter_DeviceAtlas
- Zend_UserAgent_Storage
- Zend_UserAgent_Storage_NonPersistent
- Zend_UserAgent_Storage_Session
The first adapter provided will be Zend_UserAgent_Features_Adapter_WurflPhpApi http://wurfl.sourceforge.net/nphp/
15 Comments
comments.show.hideAug 03, 2010
Dolf Schimmel (Freeaqingme)
Wouldn't it be better to implement this as a viewhelper?
Aug 09, 2010
Matthew Weier O'Phinney
Not necessarily. It's often good to get the browser capability detection before any views or layouts are rendered, as it allows you to choose which ones you want to use. (Think ContextSwitch here – browser detection can be used instead of an XHR header or a "format" query parameter.)
Aug 18, 2010
Business&Decision / Interakting
The aim of this component is to provide the necessary informations to make conditional code for multi support display (and of course for the mobile support which is the most relevant target).
This adaptation can be done before or after the view rendering.
As a standalone component it can be anyway used as a viewhelper.
Aug 04, 2010
Martin Keckeis
Hello,
i wanted to start also this proposal today, but it seems that u we're faster
I think the name of the class is "wrong", it thould be "Zend_User" or something like that, because the information is not only from the browser:
Aug 05, 2010
Boris Guéry
Hi,
I agree with Martin Keckeis.
By the way, as the extending class are not only browser, UserAgent could be appropriate.
Aug 09, 2010
Matthew Weier O'Phinney
UserAgent makes sense as a name to me. "User" is too short and ambiguous; browser is perhaps too narrow.
Aug 18, 2010
Business&Decision / Interakting
Everyone seems to agree for "Zend_UserAgent".
I will update the Class Index to :
•Zend_UserAgent
•Zend_UserAgent_Abstract
•Zend_UserAgent_Bot
•Zend_UserAgent_Checker
•Zend_UserAgent_Console
•Zend_UserAgent_Desktop (by default)
•Zend_UserAgent_Email
•Zend_UserAgent_Feed
•Zend_UserAgent_Mobile
•Zend_UserAgent_Offline
•Zend_UserAgent_Spam
•Zend_UserAgent_Tablet
•Zend_UserAgent_Text
•Zend_UserAgent_Validator
(inspired by the lists provided by http://www.useragentstring.com/pages/useragentstring.php and http://user-agent-string.info/list-of-ua)
•Zend_UserAgent_Features_Adapter_WurflApi (the first adapter to be provided)
•Zend_UserAgent_Features_Adapter_DeviceAtlas
•Zend_UserAgent_Features_Adapter_Interface
•Zend_UserAgent_Features_Adapter_TeraWurfl
•Zend_UserAgent_Features_Adapter_Wurfl
NOTE : the "Features" classes must be independant on user-agent's type because, for example, the Wurfl API can provide capabilities for mobile/desktop/bot and spider browsers (see http://dev.wurflpro.com/projects/wurfl-api/browser/php/core/trunk/examples/resources/web_browsers_patch.xml and http://dev.wurflpro.com/projects/wurfl-api/browser/php/core/trunk/examples/resources/bots_and_spider.xml).
Aug 19, 2010
Pádraic Brady
The proposer should note that all future proposals should target Zend Framework 2.0 since ZF 1.11 will be the final release accepting new features in the 1.x branch. ZF 1.x proposals cannot be reviewed until they are updated accordingly. For your information, Zend Framework 2.0 is written for PHP 5.3 and utilises namespaces - updating code for this is not as hard as it seems
.
Paddy
Community Review (CR) Team
Aug 19, 2010
Matthew Weier O'Phinney
Actually, Paddy – this is a Zend partner, and they have agreed to be able to prepare the proposal and code in time for 1.11. I'd like to discuss this with the CR-Team today, if possible.
Aug 20, 2010
Ben Scholzen
I'd suggest to rename the component to Zend_Http_UserAgent.
Aug 24, 2010
Dolf Schimmel (Freeaqingme)
The CR Team recommends this component be included into versions 1.11 and 2.0 of the Zend Framework with the following requirements:
Sep 17, 2010
Kazusuke Sasezaki
Hi, CR-Team.
Is there any reason which should be renaming to Zend_Http_UserAgent?
Currently, Zend_Http_* is a side where sending request.Zend_Http_* should be no where request is received?
Sep 18, 2010
Matthew Weier O'Phinney
This functionality of the proposed component is not restricted to use in the MVC, but falls under the HTTP protocol (as a combination of HTTP request headers are inspected).
Zend_Http has primarily been an area of the Client in the past. However, it was never intended to be only for HTTP client purposes; at one point, a Server was considered. As such, this is a perfect location for this new component.
Sep 17, 2010
Kazusuke Sasezaki
I think that these classes should be written to be cooperate with the Zend_Controller_Request_Http and User's Controller_Request_HttpTestCase.
So, I propose a defining proxy-class, instead of $_SERVER. as follows.
current code will be change as follows?
if (isset ( $_SERVER ["REMOTE_ADDR"] )) {
?
$server = $this->getServer();
if (isset ( $server["REMOTE_ADDR"] )) {
Sep 18, 2010
Matthew Weier O'Phinney
There's no reason to tie it to Zend_Controller_Request_Http at all. That class has a getServer() method already, and the return of that may be passed in to Zend_Http_UserAgent to introspect.