Useragent.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_Application
  17. * @subpackage Resource
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Application
  24. * @subpackage Resource
  25. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class Zend_Application_Resource_UserAgent extends Zend_Application_Resource_ResourceAbstract
  29. {
  30. /**
  31. * @var Zend_Http_UserAgent
  32. */
  33. protected $_userAgent;
  34. /**
  35. * Intialize resource
  36. *
  37. * @return Zend_Http_UserAgent
  38. */
  39. public function init()
  40. {
  41. $userAgent = $this->getUserAgent();
  42. // Optionally seed the UserAgent view helper
  43. $bootstrap = $this->getBootstrap();
  44. if ($bootstrap->hasResource('view') || $bootstrap->hasPluginResource('view')) {
  45. $bootstrap->bootstrap('view');
  46. $view = $bootstrap->getResource('view');
  47. if (null !== $view) {
  48. $view->userAgent($userAgent);
  49. }
  50. }
  51. return $userAgent;
  52. }
  53. /**
  54. * Get UserAgent instance
  55. *
  56. * @return Zend_Http_UserAgent
  57. */
  58. public function getUserAgent()
  59. {
  60. if (null === $this->_userAgent) {
  61. $options = $this->getOptions();
  62. $this->_userAgent = new Zend_Http_UserAgent($options);
  63. }
  64. return $this->_userAgent;
  65. }
  66. }