UserAgent.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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-2012 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-2012 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. * UserAgent instance
  35. *
  36. * @var Zend_Http_UserAgent
  37. */
  38. protected $_userAgent = null;
  39. /**
  40. * Helper method: retrieve or set UserAgent instance
  41. *
  42. * @param null|Zend_Http_UserAgent $userAgent
  43. * @return Zend_Http_UserAgent
  44. */
  45. public function userAgent(Zend_Http_UserAgent $userAgent = null)
  46. {
  47. if (null !== $userAgent) {
  48. $this->setUserAgent($userAgent);
  49. }
  50. return $this->getUserAgent();
  51. }
  52. /**
  53. * Set UserAgent instance
  54. *
  55. * @param Zend_Http_UserAgent $userAgent
  56. * @return Zend_View_Helper_UserAgent
  57. */
  58. public function setUserAgent(Zend_Http_UserAgent $userAgent)
  59. {
  60. $this->_userAgent = $userAgent;
  61. return $this;
  62. }
  63. /**
  64. * Retrieve UserAgent instance
  65. *
  66. * If none set, instantiates one using no configuration
  67. *
  68. * @return Zend_Http_UserAgent
  69. */
  70. public function getUserAgent()
  71. {
  72. if (null === $this->_userAgent) {
  73. require_once 'Zend/Http/UserAgent.php';
  74. $this->setUserAgent(new Zend_Http_UserAgent());
  75. }
  76. return $this->_userAgent;
  77. }
  78. }