2
0

UserAgent.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_View_Helper_Abstract */
  22. require_once 'Zend/View/Helper/Abstract.php';
  23. /**
  24. * Helper for interacting with UserAgent instance
  25. *
  26. * @package Zend_View
  27. * @subpackage Helper
  28. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. */
  31. class Zend_View_Helper_UserAgent extends Zend_View_Helper_Abstract
  32. {
  33. /**
  34. * Helper method: retrieve or set UserAgent instance
  35. *
  36. * @param null|Zend_Http_UserAgent $userAgent
  37. * @return Zend_Http_UserAgent
  38. */
  39. public function userAgent(Zend_Http_UserAgent $userAgent = null)
  40. {
  41. if (null !== $userAgent) {
  42. $this->setUserAgent($userAgent);
  43. }
  44. return $this->getUserAgent();
  45. }
  46. /**
  47. * Set UserAgent instance
  48. *
  49. * @param Zend_Http_UserAgent $userAgent
  50. * @return Zend_View_Helper_UserAgent
  51. */
  52. public function setUserAgent(Zend_Http_UserAgent $userAgent)
  53. {
  54. $this->_userAgent = $userAgent;
  55. return $this;
  56. }
  57. /**
  58. * Retrieve UserAgent instance
  59. *
  60. * If none set, instantiates one using no configuration
  61. *
  62. * @return Zend_Http_UserAgent
  63. */
  64. public function getUserAgent()
  65. {
  66. if (null === $this->_userAgent) {
  67. require_once 'Zend/Http/UserAgent.php';
  68. $this->setUserAgent(new Zend_Http_UserAgent());
  69. }
  70. return $this->_userAgent;
  71. }
  72. }