As of version 1.12 Zend_Http_UserAgent_Mobile constant DEFAULT_FEATURES_ADAPTER_CLASSNAME now specifies that Zend_Http_UserAgent_Features_Adapter_Browscap is now the default mobile adapter.
How to use Zend Framework UserAgent Browscap Implementation
Here I will outline 2 methods of using browscap in your Zend Framework application. One prior to the release of Zend Framework version 1.12 and after the release.
1) Set-up Browscap in your PHP Installation
This step is very important. It is not obvious, but Browscap is unlikely to be already installed in your PHP distribution. But that’s easy to fix. You should download the full_php_browscap.ini file and place it somewhere on your file system. I chose the standard php include path, which on my system is /usr/share/php/.
Then place this line in your php.ini file (at the very bottom):
browscap = /usr/share/php/browscap.ini
Important: Bounce (restart) Apache.
2) Set-up your Browscap – Before ZF Version 1.12 Release
For those who would like to start using Browscap prior to upgrading to Zend Framework version 1.12, we cave copied the Browscap implementation temporarily to the YinYang ZF PHP Library.
Place the YinYang folder from the YinYang’s library folder in your ZF application’s library folder. Here’s a quick subversion export command to save you some time:
ubuntu ~/my-zend-framework-app/library/ $ svn export --force http://yinyang.googlecode.com/svn/tags/2.4/library/YinYang/ YinYang
Now add this line to your application’s Bootstrap file to enable the YinYang ZF PHP Library:
[production] autoloaderNamespaces = "YinYang"
Finally, we need to add the following to the application.ini file to make this work and use the YinYang class:
[production] resources.useragent.mobile.features.path = "YinYang/Http/UserAgent/Features/Adapter/Browscap.php" resources.useragent.mobile.features.classname = "YinYang_Http_UserAgent_Features_Adapter_Browscap" [development : production] resources.useragent.storage.adapter = "Zend_Http_UserAgent_Storage_NonPersistent"
Just to explain this. We are telling the Zend_Http_UserAgent component to use the YinYang_Http_UserAgent_Features_Adapter_Browscap class in the mean time. The next line tells the Zend_Http_UserAgent component not to cache anything. This is critical for development purposes.
3) Set-up your Browscap – After ZF Version 1.12 Release
After Zend Framework 1.12 is released, you can remove all of the entries in step 2. As stated above, as of version 1.12, Zend_Http_UserAgent_Mobile constant DEFAULT_FEATURES_ADAPTER_CLASSNAME now specifies that Zend_Http_UserAgent_Features_Adapter_Browscap is now the default mobile adapter.
However, you will need to keep what you did in step 1 as the browscap INI file is crucial to using Browscap.