2
0

Zend_Http_UserAgent-Features_Browscap.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.http.user-agent-features-browscap">
  4. <title>The Browscap UserAgent Features Adapter</title>
  5. <sect2 id="zend.http.user-agent-features-browscap.intro">
  6. <title>Overview</title>
  7. <para>
  8. <ulink url="http://browsers.garykeith.com/">Browscap</ulink> is an open project
  9. dedicated to collecting an disseminating a "database" of browser capabilities --
  10. actually a set of different files describing browser capablities. PHP has built-in
  11. support for using these files via the <ulink
  12. url="http://php.net/get_browser"><function>get_browser()</function></ulink>
  13. function. This function requires that your <filename>php.ini</filename> provides a
  14. <varname>browscap</varname> entry pointing to the PHP-specific
  15. <filename>php_browscap.ini</filename> file, which <ulink
  16. url="http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI">you can download from
  17. the browscap site</ulink>.
  18. </para>
  19. <para>
  20. This class provides a <link linkend="zend.http.user-agent-features">features
  21. adapter</link> that calls <function>get_browser()</function> in order to discover
  22. mobile device capabilities to inject into <classname>UserAgent</classname> device
  23. instances.
  24. </para>
  25. <note id="zend.http.user-agent-features-browscap.intro.browscap-usage">
  26. <title>You may need to restart your webserver</title>
  27. <para>
  28. The <varname>browscap</varname> <filename>php.ini</filename> setting is a
  29. <constant>PHP_INI_SYSTEM</constant> setting, meaning it can only be set in your
  30. <filename>php.ini</filename> file or in your web server configuration. As such, you
  31. may need to restart your web server after adding the entry.
  32. </para>
  33. </note>
  34. </sect2>
  35. <sect2 id="zend.http.user-agent-features-browscap.quick-start">
  36. <title>Quick Start</title>
  37. <para>
  38. First, if you haven't already, <ulink
  39. url="http://browsers.garykeith.com/stream.asp?PHP_BrowsCapINI">download the
  40. php_browscap.ini file</ulink>, and put it somewhere your web server can access it;
  41. make sure the web server has permissions to read the file. Typically, you'll place this
  42. in the same location as your <filename>php.ini</filename> file.
  43. </para>
  44. <para>
  45. Next, update your <filename>php.ini</filename> file to add the following line:
  46. </para>
  47. <programlisting language="ini"><![CDATA[
  48. browscap = /path/to/php_browscap.ini
  49. ]]></programlisting>
  50. <note>
  51. <title>Keep it simple</title>
  52. <para>
  53. If you put your <filename>php_browscap.ini</filename> file next to the
  54. <filename>php.ini</filename> file, you can omit the path information, and simply
  55. specify the filename.
  56. </para>
  57. </note>
  58. <para>
  59. Next, simply provide configuration to your application as follows:
  60. </para>
  61. <programlisting language="ini"><![CDATA[
  62. resources.useragent.mobile.features.classname = "Zend_Http_UserAgent_Device_Features_Browscap"
  63. ]]></programlisting>
  64. <para>
  65. At this point, you're all set. You can access the browser information in a variety of
  66. ways. From within the MVC portion of your application, you can access it via the
  67. bootstrap. Within plugins, this is done by grabbing the bootstrap from the front
  68. controller.
  69. </para>
  70. <programlisting language="php"><![CDATA[
  71. $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
  72. $userAgent = $bootstrap->getResource('useragent');
  73. ]]></programlisting>
  74. <para>
  75. From your action controller, use <methodname>getInvokeArg()</methodname> to grab the
  76. bootstrap, and from there, the user agent object.
  77. </para>
  78. <programlisting language="php"><![CDATA[
  79. $bootstrap = $this->getInvokeArg('bootstrap');
  80. $userAgent = $bootstrap->getResource('useragent');
  81. ]]></programlisting>
  82. <para>
  83. Within your view, you can grab it using the <classname>UserAgent</classname> view
  84. helper.
  85. </para>
  86. <programlisting language="php"><![CDATA[
  87. $userAgent = $this->userAgent();
  88. ]]></programlisting>
  89. <para>
  90. Once you have the user agent object, you can query it for different capabilities. As one
  91. example, you may want to use an alternate layout script based on the user agent
  92. capabilities.
  93. </para>
  94. <programlisting language="php"><![CDATA[
  95. $device = $userAgent->getDevice();
  96. $cssSupport = $device->getFeature('cssversion');
  97. $jsSupport = $device->getFeature('javascript');
  98. switch (true) {
  99. case ($jsSupport && $cssSupport >= 3):
  100. $layout->setLayout('layout-html5');
  101. break;
  102. case ($jsSupport && $cssSupport < 3):
  103. $layout->setLayout('layout-xhtml');
  104. break;
  105. case (!$jsSupport && $cssSupport < 3):
  106. $layout->setLayout('layout-html-transitional');
  107. break;
  108. default:
  109. $layout->setLayout('layout-web-1');
  110. break;
  111. }
  112. ]]></programlisting>
  113. </sect2>
  114. <sect2 id="zend.http.user-agent-features-browscap.options">
  115. <title>Configuration Options</title>
  116. <para>
  117. The browscap adapter has no configuration options.
  118. </para>
  119. </sect2>
  120. <sect2 id="zend.http.user-agent-features-browscap.methods">
  121. <title>Available Methods</title>
  122. <variablelist>
  123. <varlistentry id="zend.http.user-agent-features-browscap.methods.get-from-request">
  124. <term>
  125. <methodsynopsis>
  126. <methodname>getFromRequest</methodname>
  127. <methodparam>
  128. <funcparams>array $request, array $config</funcparams>
  129. </methodparam>
  130. </methodsynopsis>
  131. </term>
  132. <listitem>
  133. <para>
  134. Decompose the request in order to return an array of device capabilities.
  135. </para>
  136. </listitem>
  137. </varlistentry>
  138. </variablelist>
  139. </sect2>
  140. </sect1>