Zend_Http_UserAgent.xml 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.http.user-agent">
  4. <title>Zend_Http_UserAgent</title>
  5. <sect2 id="zend.http.user-agent.intro">
  6. <title>Overview</title>
  7. <para>
  8. With the plethora of mobile devices available on the market, it's increasingly important
  9. to be able to identify the capabilities of those devices in order to present content in
  10. a an appropriate way. For instance, if the device is not capable of displaying images,
  11. you might want to omit them from the markup; alternately, if a device is capable of
  12. Flash, you may want to provide a Flash-based user interface.
  13. </para>
  14. <para>
  15. The process of identifying a device's capabilities typically first requires knowing the
  16. HTTP User Agent, and then comparing that user agent against a database of user agent
  17. capabilities. <classname>Zend_Http_UserAgent</classname> was created to provide these
  18. capabilities for your applications. It consists of several major features:
  19. </para>
  20. <itemizedlist>
  21. <listitem>
  22. <para>
  23. The primary <classname>Zend_Http_UserAgent</classname> class, which detects the
  24. User Agent, and gives you a device object, as well as persists the device object
  25. for later retrieval.
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. A <link linkend="zend.http.user-agent-device">Zend_Http_UserAgent_Device</link>
  31. interface, and a number of implementations that implement it. These objects
  32. utilize a features adatper to discover device capabilities, and then allow you
  33. to introspect those capabilities.
  34. </para>
  35. </listitem>
  36. <listitem>
  37. <para>
  38. A <link linkend="zend.http.user-agent-features">Zend_Http_UserAgent_Features_Adapter</link>
  39. interface; concrete implementations provide the ability to discover device
  40. capabilities, or features.
  41. </para>
  42. </listitem>
  43. <listitem>
  44. <para>
  45. A <link linkend="zend.http.user-agent-storage">Zend_Http_UserAgent_Storage</link>
  46. interface, which is used to persist discovered devices for given users, allowing
  47. for faster device capability discovery on subsequent page visits.
  48. </para>
  49. </listitem>
  50. <listitem>
  51. <para>
  52. A <link linkend="zend.view.helpers.initial.user-agent">view helper</link> that
  53. can be used within your view scripts and layouts to branch display logic based
  54. on device capabilities.
  55. </para>
  56. </listitem>
  57. <listitem>
  58. <para>
  59. A <classname>Zend_Application</classname> <link
  60. linkend="zend.application.available-resources.useragent">resource</link> for
  61. configuring and instantiating the user agent object, as well as seeding the view
  62. helper with the user agent object instance.
  63. </para>
  64. </listitem>
  65. </itemizedlist>
  66. <para>
  67. At the time of this writing, The <classname>UserAgent</classname> component provides
  68. three adapters:
  69. </para>
  70. <itemizedlist>
  71. <listitem>
  72. <para>
  73. <link
  74. linkend="zend.http.user-agent-features-wurfl">Zend_Http_UserAgent_Features_Adapter_Wurfl</link>
  75. consumes the <ulink url="http://wurfl.sourceforge.net/">WURFL</ulink> (Wireless
  76. Universal Resource File) PHP API. This database is considered one of the most
  77. comprehensive mobile device capabilities databases available.
  78. </para>
  79. </listitem>
  80. <listitem>
  81. <para>
  82. <link
  83. linkend="zend.http.user-agent-features-tera-wurfl">Zend_Http_UserAgent_Features_Adapter_TeraWurfl</link>
  84. consumes the TeraWurfl API, which is built on top of <acronym>WURFL</acronym>,
  85. and aimed at providing a highly available, highly performant lookup mechanism.
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <link
  91. linkend="zend.http.user-agent-features-device-atlas">Zend_Http_UserAgent_Features_Adapter_DeviceAtlas</link>
  92. consumes the DeviceAtlas API, which is a paid, Enterprise-grade mobile device
  93. capabilities database.
  94. </para>
  95. </listitem>
  96. </itemizedlist>
  97. </sect2>
  98. <sect2 id="zend.http.user-agent.quick-start">
  99. <title>Quick Start</title>
  100. <para>
  101. First, you will need to download the following:
  102. </para>
  103. <itemizedlist>
  104. <listitem>
  105. <para>
  106. The <acronym>WURFL</acronym> <ulink
  107. url="http://sourceforge.net/projects/wurfl/files/WURFL%20PHP/1.1/wurfl-php-1.1.tar.gz/download">PHP
  108. API</ulink>. This archive contains the most recent
  109. <filename>wurfl-latest.xml</filename> file and patches which constitute the
  110. actual <acronym>WURFL</acronym> database.
  111. </para>
  112. </listitem>
  113. </itemizedlist>
  114. <para>
  115. We suggest that you inflate this archive in your "library" directory. Inflating the
  116. archive will create a <filename>wurfl-php-1.1</filename> directory.
  117. </para>
  118. <programlisting language="text"><![CDATA[
  119. library
  120. |-- wurfl-php-1.1
  121. | |-- COPYING
  122. | |-- docs
  123. | |-- examples
  124. | |-- README
  125. | |-- tests
  126. | `-- WURFL
  127. ]]></programlisting>
  128. <para>
  129. Next, create a data and cache directory for the <acronym>WURFL</acronym> database and
  130. related cache files; this should be done from your project root (the directory
  131. containing the <filename>application</filename> and <filename>library</filename>
  132. directories). When you do so, make sure the directory is at least writable by the web
  133. server user; the following makes it writable for all users.
  134. </para>
  135. <programlisting language="sh"><![CDATA[
  136. mkdir -p data/wurfl/cache
  137. chmod -R o+rwX data/wurfl/cache
  138. ]]></programlisting>
  139. <para>
  140. Now, copy the <acronym>WURFL</acronym> data from the inflated archive into your data
  141. directory.
  142. </para>
  143. <programlisting language="sh"><![CDATA[
  144. cp library/wurfl-php-1.1/tests/resources/wurfl-latest.zip data/wurfl/
  145. cp library/wurfl-php-1.1/tests/resources/web_browsers_patch.xml data/wurfl/
  146. ]]></programlisting>
  147. <para>
  148. Create a <acronym>WURFL</acronym> configuration file named
  149. <filename>application/configs/wurfl-config.php</filename>, with the following contents:
  150. </para>
  151. <programlisting language="php"><![CDATA[
  152. $resourcesDir = dirname(__FILE__) . '/../../data/wurfl/';
  153. $wurfl['main-file'] = $resourcesDir . 'wurfl-latest.zip';
  154. $wurfl['patches'] = array($resourcesDir . 'web_browsers_patch.xml');
  155. $persistence['provider'] = 'file';
  156. $persistence['dir'] = $resourcesDir . 'cache/';
  157. $cache['provider'] = null;
  158. $configuration['wurfl'] = $wurfl;
  159. $configuration['persistence'] = $persistence;
  160. $configuration['cache'] = $cache;
  161. ]]></programlisting>
  162. <para>
  163. Finally, edit your <filename>application.ini</filename> to add the following lines to your
  164. <varname>[production]</varname> section:
  165. </para>
  166. <programlisting language="ini"><![CDATA[
  167. resources.useragent.wurflapi.wurfl_api_version = "1.1"
  168. resources.useragent.wurflapi.wurfl_lib_dir = APPLICATION_PATH "/../library/wurfl-php-1.1/WURFL/"
  169. resources.useragent.wurflapi.wurfl_config_file = APPLICATION_PATH "/configs/wurfl-config.php"
  170. ]]></programlisting>
  171. <note>
  172. <para>
  173. The trailing directory separator on the <constant>wurfl_lib_dir</constant> setting
  174. is important. The <acronym>WURFL</acronym> API does no normalization, and expects
  175. it to be there.
  176. </para>
  177. </note>
  178. <para>
  179. At this point, everything is setup. The first request (from a mobile device) will populate the
  180. <acronym>WURFL</acronym> cache by parsing the <filename>resources/wurfl.xml</filename>
  181. file, and as such may take up to a minute. After that, lookups will be quite fast, and
  182. each request will contain detailed information on the user agent.
  183. </para>
  184. <para>
  185. You can access this information in a variety of ways. From within the MVC portion of
  186. your application, you can access it via the bootstrap. Within plugins, this is done by
  187. grabbing the bootstrap from the front controller.
  188. </para>
  189. <programlisting language="php"><![CDATA[
  190. $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
  191. $userAgent = $bootstrap->getResource('useragent');
  192. ]]></programlisting>
  193. <para>
  194. From your action controller, use <methodname>getInvokeArg()</methodname> to grab the
  195. bootstrap, and from there, the user agent object.
  196. </para>
  197. <programlisting language="php"><![CDATA[
  198. $bootstrap = $this->getInvokeArg('bootstrap');
  199. $userAgent = $bootstrap->getResource('useragent');
  200. ]]></programlisting>
  201. <para>
  202. Within your view, you can grab it using the <classname>UserAgent</classname> view
  203. helper.
  204. </para>
  205. <programlisting language="php"><![CDATA[
  206. $userAgent = $this->userAgent();
  207. ]]></programlisting>
  208. <para>
  209. Once you have the user agent object, you can query it for different capabilities. As one
  210. example, you may want to use an alternate layout script based on the user agent
  211. capabilities.
  212. </para>
  213. <programlisting language="php"><![CDATA[
  214. $width = $userAgent->getDevice()->getPhysicalScreenWidth();
  215. switch (true) {
  216. case ($width <= 128):
  217. $layout->setLayout('layout-poor');
  218. break;
  219. case ($width <= 176):
  220. $layout->setLayout('layout-medium');
  221. break;
  222. case ($width <= 240):
  223. $layout->setLayout('layout-high');
  224. break;
  225. case ($width <= 320):
  226. $layout->setLayout('layout-ultra');
  227. break;
  228. default:
  229. // use default
  230. break;
  231. }
  232. ]]></programlisting>
  233. <para>
  234. Finally, each device will often have a large number of capabilities not immediately
  235. represented in the device interface. You can query these using the
  236. <methodname>hasFeature()</methodname> and <methodname>getFeature()</methodname> methods.
  237. </para>
  238. <programlisting language="php"><![CDATA[
  239. if ($userAgent->hasFeature('mp3') && $userAgent->getFeature('mp3')) {
  240. // embed HTML5 audio tag...
  241. }
  242. ]]></programlisting>
  243. </sect2>
  244. <sect2 id="zend.http.user-agent.options">
  245. <title>Configuration Options</title>
  246. <variablelist>
  247. <title>UserAgent Options</title>
  248. <para>
  249. The following options may be passed to the constructor or within your application
  250. configuration. A "." indicates another layer of depth in the configuration array; as
  251. an example, assigning "wurflapi.wurfl_config_array.wurfl.main-file" as part of a PHP
  252. configuration would require the following definition:
  253. </para>
  254. <programlisting language="php"><![CDATA[
  255. $config = array(
  256. 'wurflapi' => array(
  257. 'wurfl_config_array' => array(
  258. 'wurfl' => array(
  259. 'main-file' => 'path/to/some/file',
  260. ),
  261. ),
  262. ),
  263. );
  264. ]]></programlisting>
  265. <para>
  266. Each features adapter has its own options available as well, which may be mixed in
  267. with the general UserAgent options.
  268. </para>
  269. <varlistentry>
  270. <term>browser_type</term>
  271. <listitem>
  272. <para>
  273. Used to seed the list of devices the component will search. See also
  274. <varname>identification_sequence</varname>; this value will be prepended to
  275. that list during user agent device discovery.
  276. </para>
  277. </listitem>
  278. </varlistentry>
  279. <varlistentry>
  280. <term>http_accept</term>
  281. <listitem>
  282. <para>
  283. The value of the <varname>Accept</varname> <acronym>HTTP</acronym> header;
  284. used by some user agents to determine capabilities. Set this to seed the
  285. value explicitly.
  286. </para>
  287. </listitem>
  288. </varlistentry>
  289. <varlistentry>
  290. <term>identification_sequence</term>
  291. <listitem>
  292. <para>
  293. A comma-separated list of device types to scan for matches; defaults to
  294. "mobile,desktop".
  295. </para>
  296. </listitem>
  297. </varlistentry>
  298. <varlistentry>
  299. <term>storage.adapter</term>
  300. <listitem>
  301. <para>
  302. The name of a storage adapter used to persist the device capabilities,
  303. typically within a given user session. The value may either be a fully
  304. qualified class name, or a short name to resolve by the plugin loader for
  305. storage classes. By default, uses "Session" as the value, resolving to
  306. <classname>Zend_Http_UserAgent_Storage_Session</classname>.
  307. </para>
  308. </listitem>
  309. </varlistentry>
  310. <varlistentry>
  311. <term>storage.options[]</term>
  312. <listitem>
  313. <para>
  314. An array of options to pass to the constructor of a storage adapter. By
  315. default, the option <varname>browser_type</varname> will be present.
  316. </para>
  317. </listitem>
  318. </varlistentry>
  319. <varlistentry>
  320. <term>plugin_loader.[type] = [class]</term>
  321. <listitem>
  322. <para>
  323. Plugin loader configuration; allows you to specify a pre-configured
  324. <classname>Zend_Loader_PluginLoader</classname> extension class to use for
  325. one of the plugin loader types managed by <classname>UserAgent</classname>
  326. (currently "storage" and "device".
  327. </para>
  328. </listitem>
  329. </varlistentry>
  330. <varlistentry>
  331. <term>server[]</term>
  332. <listitem>
  333. <para>
  334. Typically, you will not set this; this simply allows injection of the
  335. <varname>$_SERVER</varname> superglobal (or a filtered version of it). The
  336. value should be an associative array.
  337. </para>
  338. </listitem>
  339. </varlistentry>
  340. <varlistentry>
  341. <term>user_agent</term>
  342. <listitem>
  343. <para>
  344. The actual <acronym>HTTP</acronym> User-Agent string you wish to try and
  345. match. Typically, this will be auto-discovered from the
  346. <varname>server</varname> array.
  347. </para>
  348. </listitem>
  349. </varlistentry>
  350. <varlistentry>
  351. <term>[browser_type].device.classname</term>
  352. <listitem>
  353. <para>
  354. The device class to use for a given browser type; typically,
  355. <varname>browser_type</varname> will be one of the supported browser
  356. devices, including:
  357. </para>
  358. <itemizedlist>
  359. <listitem><para>Bot</para></listitem>
  360. <listitem><para>Checker</para></listitem>
  361. <listitem><para>Console</para></listitem>
  362. <listitem><para>Desktop</para></listitem>
  363. <listitem><para>Email</para></listitem>
  364. <listitem><para>Feed</para></listitem>
  365. <listitem><para>Mobile</para></listitem>
  366. <listitem><para>Offline</para></listitem>
  367. <listitem><para>Probe</para></listitem>
  368. <listitem><para>Spam</para></listitem>
  369. <listitem><para>Text</para></listitem>
  370. <listitem><para>Validator</para></listitem>
  371. </itemizedlist>
  372. <para>
  373. The <varname>browser_type</varname> should be normalized to lowercase for
  374. configuration purposes.
  375. </para>
  376. </listitem>
  377. </varlistentry>
  378. <varlistentry>
  379. <term>[browser_type].device.path and [browser_type].device.prefix</term>
  380. <listitem>
  381. <para>
  382. An alternate way to specify the device class for a given browser type is to
  383. assume it is named after the device, and that all device classes are in the
  384. same path sharing the same prefix. Configure the prefix and path using these
  385. keys.
  386. </para>
  387. <para>
  388. As an example, the following would look for a class named
  389. "Mobile_Device_Bot" on the path "Mobile/Device/" under the application
  390. library.
  391. </para>
  392. <programlisting language="ini"><![CDATA[
  393. resources.useragent.bot.device.path = APPLICATION_PATH '/../library/Mobile/Device"
  394. resources.useragent.bot.device.prefix = "Mobile_Device"
  395. ]]></programlisting>
  396. </listitem>
  397. </varlistentry>
  398. <varlistentry>
  399. <term>[browser_type].features.path and [browser_type].features.classname</term>
  400. <listitem>
  401. <para>
  402. These settings are used to load the features capabilities detection class
  403. for a given browser type. The class will be named using the
  404. <varname>classname</varname> key, and is expected to exist in the file
  405. denoted by the <varname>path</varname> key. The class should implement
  406. <classname>Zend_Http_UserAgent_Features_Adapter</classname>.
  407. </para>
  408. </listitem>
  409. </varlistentry>
  410. <varlistentry>
  411. <term>wurflapi.wurfl_api_version</term>
  412. <listitem>
  413. <para>
  414. If using the <acronym>WURFL</acronym> API, use this key to specify which
  415. version you are using; typically, this will be either "1.0" or "1.1".
  416. </para>
  417. </listitem>
  418. </varlistentry>
  419. <varlistentry>
  420. <term>wurflapi.wurfl_lib_dir</term>
  421. <listitem>
  422. <para>
  423. If using the <acronym>WURFL</acronym> API, use this key to specify in which
  424. directory the library exists.
  425. </para>
  426. </listitem>
  427. </varlistentry>
  428. <varlistentry>
  429. <term>wurflapi.wurfl_config_file</term>
  430. <listitem>
  431. <para>
  432. If using the <acronym>WURFL</acronym> API, use this key to specify the
  433. location of the configuration file you will use; typically, this will be
  434. <filename>resources/wurfl-config.php</filename> within the
  435. <varname>wurfl_lib_dir</varname>.
  436. </para>
  437. </listitem>
  438. </varlistentry>
  439. <varlistentry>
  440. <term>wurflapi.wurfl_config_array.wurfl.main-file</term>
  441. <listitem>
  442. <para>
  443. If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
  444. a <varname>wurfl_config_file</varname>, and instead provide an associative
  445. array of configuration values. This particular value indicates the location
  446. of the <filename>wurfl.xml</filename> file containing the actual
  447. <acronym>WURFL</acronym> database.
  448. </para>
  449. </listitem>
  450. </varlistentry>
  451. <varlistentry>
  452. <term>wurflapi.wurfl_config_array.wurfl.patches[]</term>
  453. <listitem>
  454. <para>
  455. If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
  456. a <varname>wurfl_config_file</varname>, and instead provide an associative
  457. array of configuration values. This particular value is an array of file
  458. locations containing patchfiles for the <varname>wurfl.main-file</varname>
  459. (which are used to ammend and extend the primary database file).
  460. </para>
  461. </listitem>
  462. </varlistentry>
  463. <varlistentry>
  464. <term>wurflapi.wurfl_config_array.persistence.provider</term>
  465. <listitem>
  466. <para>
  467. If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
  468. a <varname>wurfl_config_file</varname>, and instead provide an associative
  469. array of configuration values. This particular value indicates the type of
  470. persistence provider used when caching discovered capabilities. See the
  471. <acronym>WURFL</acronym> documentation for potential values; "file" is a
  472. known good value.
  473. </para>
  474. </listitem>
  475. </varlistentry>
  476. <varlistentry>
  477. <term>wurflapi.wurfl_config_array.persistence.dir</term>
  478. <listitem>
  479. <para>
  480. If using version 1.1 of the <acronym>WURFL</acronym> API, you can omit using
  481. a <varname>wurfl_config_file</varname>, and instead provide an associative
  482. array of configuration values. This particular value indicates the location
  483. where the persistence provider will cache discovered capabilities.
  484. </para>
  485. </listitem>
  486. </varlistentry>
  487. </variablelist>
  488. </sect2>
  489. <sect2 id="zend.http.user-agent.methods">
  490. <title>Available Methods</title>
  491. <variablelist>
  492. <varlistentry id="zend.http.user-agent.methods.constructor">
  493. <term>
  494. <methodsynopsis>
  495. <methodname>__construct</methodname>
  496. <methodparam>
  497. <funcparams>$options = null</funcparams>
  498. </methodparam>
  499. </methodsynopsis>
  500. </term>
  501. <listitem>
  502. <para>
  503. The constructor attempts to determine the current User-Agent based on the
  504. options provided, the current request information, and/or previously discovered
  505. information persisted in storage. Once instantiated, the detected device is
  506. immediately available.
  507. </para>
  508. <para>
  509. Please see <link linkend="zend.http.user-agent.options">configuration
  510. options</link> section for details on the <varname>$options</varname> array.
  511. </para>
  512. </listitem>
  513. </varlistentry>
  514. <varlistentry id="zend.http.user-agent.methods.serialize">
  515. <term>
  516. <methodsynopsis>
  517. <methodname>serialize</methodname>
  518. <methodparam>
  519. <funcparams></funcparams>
  520. </methodparam>
  521. </methodsynopsis>
  522. </term>
  523. <listitem>
  524. <para>
  525. Defined by the <interfacename>Serializable</interfacename> interface, this
  526. method performs logic necessary to determine what within the object should be
  527. serialized when the object is serialized by a storage adapter.
  528. </para>
  529. </listitem>
  530. </varlistentry>
  531. <varlistentry id="zend.http.user-agent.methods.unserialize">
  532. <term>
  533. <methodsynopsis>
  534. <methodname>unserialize</methodname>
  535. <methodparam>
  536. <funcparams>$serialized</funcparams>
  537. </methodparam>
  538. </methodsynopsis>
  539. </term>
  540. <listitem>
  541. <para>
  542. Defined by the <interfacename>Serializable</interfacename> interface, this
  543. method performs logic necessary to determine how to unserialize a previously
  544. serialized instance.
  545. </para>
  546. </listitem>
  547. </varlistentry>
  548. <varlistentry id="zend.http.user-agent.methods.set-options">
  549. <term>
  550. <methodsynopsis>
  551. <methodname>setOptions</methodname>
  552. <methodparam>
  553. <funcparams>$options</funcparams>
  554. </methodparam>
  555. </methodsynopsis>
  556. </term>
  557. <listitem>
  558. <para>
  559. Initializes object state. Please see the <link
  560. linkend="zend.http.user-agent.options">configuration options</link> section
  561. for information on the <varname>$options</varname> array.
  562. </para>
  563. </listitem>
  564. </varlistentry>
  565. <varlistentry id="zend.http.user-agent.methods.get-user-agent">
  566. <term>
  567. <methodsynopsis>
  568. <methodname>getUserAgent</methodname>
  569. <methodparam>
  570. <funcparams></funcparams>
  571. </methodparam>
  572. </methodsynopsis>
  573. </term>
  574. <listitem>
  575. <para>
  576. Retrieve the discovered User-Agent string. Unless set explicitly, this will be
  577. autodiscovered from the server array.
  578. </para>
  579. </listitem>
  580. </varlistentry>
  581. <varlistentry id="zend.http.user-agent.methods.set-user-agent">
  582. <term>
  583. <methodsynopsis>
  584. <methodname>setUserAgent</methodname>
  585. <methodparam>
  586. <funcparams>$userAgent</funcparams>
  587. </methodparam>
  588. </methodsynopsis>
  589. </term>
  590. <listitem>
  591. <para>
  592. Set the User-Agent string explicitly. Once <methodname>getDevice()</methodname>
  593. has been called, this property is marked immutable, and calling this method will
  594. raise an exception.
  595. </para>
  596. </listitem>
  597. </varlistentry>
  598. <varlistentry id="zend.http.user-agent.methods.get-http-accept">
  599. <term>
  600. <methodsynopsis>
  601. <methodname>getHttpAccept</methodname>
  602. <methodparam>
  603. <funcparams>$httpAccept = null</funcparams>
  604. </methodparam>
  605. </methodsynopsis>
  606. </term>
  607. <listitem>
  608. <para>
  609. Retrieve the HTTP Accept header value.
  610. </para>
  611. </listitem>
  612. </varlistentry>
  613. <varlistentry id="zend.http.user-agent.methods.set-http-accept">
  614. <term>
  615. <methodsynopsis>
  616. <methodname>setHttpAccept</methodname>
  617. <methodparam>
  618. <funcparams>$httpAccept</funcparams>
  619. </methodparam>
  620. </methodsynopsis>
  621. </term>
  622. <listitem>
  623. <para>
  624. Explicitly set the HTTP Accept header value. Once
  625. <methodname>getDevice()</methodname> has been called, this property is marked
  626. immutable, and calling this method will raise an exception.
  627. </para>
  628. </listitem>
  629. </varlistentry>
  630. <varlistentry id="zend.http.user-agent.methods.get-storage">
  631. <term>
  632. <methodsynopsis>
  633. <methodname>getStorage</methodname>
  634. <methodparam>
  635. <funcparams>$browser = null</funcparams>
  636. </methodparam>
  637. </methodsynopsis>
  638. </term>
  639. <listitem>
  640. <para>
  641. Retrieves a persistent storage object for a given browser type.
  642. </para>
  643. </listitem>
  644. </varlistentry>
  645. <varlistentry id="zend.http.user-agent.methods.set-storage">
  646. <term>
  647. <methodsynopsis>
  648. <methodname>setStorage</methodname>
  649. <methodparam>
  650. <funcparams>Zend_Http_UserAgent_Storage $storage</funcparams>
  651. </methodparam>
  652. </methodsynopsis>
  653. </term>
  654. <listitem>
  655. <para>
  656. Use this to explicitly set the peristent storage object. Once
  657. <methodname>getDevice()</methodname> has been called, the storage is marked
  658. immutable (as in: you may not inject a new storage object), and calling this
  659. method will raise an exception.
  660. </para>
  661. </listitem>
  662. </varlistentry>
  663. <varlistentry id="zend.http.user-agent.methods.clear-storage">
  664. <term>
  665. <methodsynopsis>
  666. <methodname>clearStorage</methodname>
  667. <methodparam>
  668. <funcparams>$browser = null</funcparams>
  669. </methodparam>
  670. </methodsynopsis>
  671. </term>
  672. <listitem>
  673. <para>
  674. Clears any information in the persistent storage object.
  675. </para>
  676. </listitem>
  677. </varlistentry>
  678. <varlistentry id="zend.http.user-agent.methods.get-config">
  679. <term>
  680. <methodsynopsis>
  681. <methodname>getConfig</methodname>
  682. <methodparam>
  683. <funcparams></funcparams>
  684. </methodparam>
  685. </methodsynopsis>
  686. </term>
  687. <listitem>
  688. <para>
  689. Retrieve configuration parameters.
  690. </para>
  691. </listitem>
  692. </varlistentry>
  693. <varlistentry id="zend.http.user-agent.methods.get-device">
  694. <term>
  695. <methodsynopsis>
  696. <methodname>getDevice</methodname>
  697. <methodparam>
  698. <funcparams></funcparams>
  699. </methodparam>
  700. </methodsynopsis>
  701. </term>
  702. <listitem>
  703. <para>
  704. Use this method to get the User-Agent Device object; this is the object that
  705. will contain the various discovered device capabilities.
  706. </para>
  707. <para>
  708. Discovery of the User-Agent device occurs in this method. Once the device has
  709. been retrieved, the server array, browser type, user agent, http accept, and
  710. storage properties are marked as immutable.
  711. </para>
  712. </listitem>
  713. </varlistentry>
  714. <varlistentry id="zend.http.user-agent.methods.get-browser-type">
  715. <term>
  716. <methodsynopsis>
  717. <methodname>getBrowserType</methodname>
  718. <methodparam>
  719. <funcparams></funcparams>
  720. </methodparam>
  721. </methodsynopsis>
  722. </term>
  723. <listitem>
  724. <para>
  725. Retrieve the discovered browser type; usually one of:
  726. </para>
  727. <itemizedlist>
  728. <listitem><para>Bot</para></listitem>
  729. <listitem><para>Checker</para></listitem>
  730. <listitem><para>Console</para></listitem>
  731. <listitem><para>Desktop</para></listitem>
  732. <listitem><para>Email</para></listitem>
  733. <listitem><para>Feed</para></listitem>
  734. <listitem><para>Mobile</para></listitem>
  735. <listitem><para>Offline</para></listitem>
  736. <listitem><para>Probe</para></listitem>
  737. <listitem><para>Spam</para></listitem>
  738. <listitem><para>Text</para></listitem>
  739. <listitem><para>Validator</para></listitem>
  740. </itemizedlist>
  741. <para>
  742. Unless explicitly set, the browser type is unknown until
  743. <methodname>getDevice()</methodname> has been called.
  744. </para>
  745. </listitem>
  746. </varlistentry>
  747. <varlistentry id="zend.http.user-agent.methods.set-browser-type">
  748. <term>
  749. <methodsynopsis>
  750. <methodname>setBrowserType</methodname>
  751. <methodparam>
  752. <funcparams>$browserType</funcparams>
  753. </methodparam>
  754. </methodsynopsis>
  755. </term>
  756. <listitem>
  757. <para>
  758. Explicitly set the browser type to prepend to the identification sequence. Once
  759. <methodname>getDevice()</methodname> has been called, the browser type is marked
  760. immutable, and calling this method will raise an exception.
  761. </para>
  762. </listitem>
  763. </varlistentry>
  764. <varlistentry id="zend.http.user-agent.methods.get-server">
  765. <term>
  766. <methodsynopsis>
  767. <methodname>getServer</methodname>
  768. <methodparam>
  769. <funcparams></funcparams>
  770. </methodparam>
  771. </methodsynopsis>
  772. </term>
  773. <listitem>
  774. <para>
  775. Retrieve the array of HTTP headers and environment variables used to perform
  776. device discovery. If the array has not yet been set, it is seeded with the
  777. <varname>$_SERVER</varname> superglobal.
  778. </para>
  779. </listitem>
  780. </varlistentry>
  781. <varlistentry id="zend.http.user-agent.methods.set-server">
  782. <term>
  783. <methodsynopsis>
  784. <methodname>setServer</methodname>
  785. <methodparam>
  786. <funcparams>$server</funcparams>
  787. </methodparam>
  788. </methodsynopsis>
  789. </term>
  790. <listitem>
  791. <para>
  792. Explicitly set the "server" array of HTTP headers and environment variables to
  793. use during device discovery. Once <methodname>getDevice()</methodname> has been
  794. called, the server array is marked immutable, and calling this method will raise
  795. an exception.
  796. </para>
  797. </listitem>
  798. </varlistentry>
  799. <varlistentry id="zend.http.user-agent.methods.get-server-value">
  800. <term>
  801. <methodsynopsis>
  802. <methodname>getServerValue</methodname>
  803. <methodparam>
  804. <funcparams>$key</funcparams>
  805. </methodparam>
  806. </methodsynopsis>
  807. </term>
  808. <listitem>
  809. <para>
  810. Retrieve a single value from the server array by key.
  811. </para>
  812. </listitem>
  813. </varlistentry>
  814. <varlistentry id="zend.http.user-agent.methods.set-server-value">
  815. <term>
  816. <methodsynopsis>
  817. <methodname>setServerValue</methodname>
  818. <methodparam>
  819. <funcparams>$key, $value</funcparams>
  820. </methodparam>
  821. </methodsynopsis>
  822. </term>
  823. <listitem>
  824. <para>
  825. Overwrite or define a value in the internal server array. Once
  826. <methodname>getDevice()</methodname> has been called, the server array is marked
  827. immutable, and calling this method will raise an exception.
  828. </para>
  829. </listitem>
  830. </varlistentry>
  831. <varlistentry id="zend.http.user-agent.methods.set-plugin-loader">
  832. <term>
  833. <methodsynopsis>
  834. <methodname>setPluginLoader</methodname>
  835. <methodparam>
  836. <funcparams>$type, $loader</funcparams>
  837. </methodparam>
  838. </methodsynopsis>
  839. </term>
  840. <listitem>
  841. <para>
  842. <varname>$type</varname> may be one of "device" or "storage; the former is used
  843. when attempting to find device classes, the latter for finding storage classes.
  844. <varname>$loader</varname> may be a
  845. <classname>Zend_Loader_PluginLoader</classname> instance, or a string name
  846. containing the classname of a <classname>Zend_Loader_PluginLoader</classname>
  847. extension class.
  848. </para>
  849. </listitem>
  850. </varlistentry>
  851. <varlistentry id="zend.http.user-agent.methods.get-plugin-loader">
  852. <term>
  853. <methodsynopsis>
  854. <methodname>getPluginLoader</methodname>
  855. <methodparam>
  856. <funcparams>$type</funcparams>
  857. </methodparam>
  858. </methodsynopsis>
  859. </term>
  860. <listitem>
  861. <para>
  862. Retrieves either the "device" or "storage" plugin loader instance.
  863. </para>
  864. </listitem>
  865. </varlistentry>
  866. </variablelist>
  867. </sect2>
  868. <sect2 id="zend.http.user-agent.examples">
  869. <title>Examples</title>
  870. <para>
  871. Please see the <link linkend="zend.http.user-agent.quick-start">quick start</link> for
  872. examples at this time.
  873. </para>
  874. </sect2>
  875. </sect1>