View.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Application_Resource_ResourceAbstract
  24. */
  25. require_once 'Zend/Application/Resource/ResourceAbstract.php';
  26. /**
  27. * Resource for settings view options
  28. *
  29. * @uses Zend_Application_Resource_ResourceAbstract
  30. * @category Zend
  31. * @package Zend_Application
  32. * @subpackage Resource
  33. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceAbstract
  37. {
  38. /**
  39. * @var Zend_View_Interface
  40. */
  41. protected $_view;
  42. /**
  43. * Defined by Zend_Application_Resource_Resource
  44. *
  45. * @return Zend_View
  46. */
  47. public function init()
  48. {
  49. $view = $this->getView();
  50. $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
  51. $viewRenderer->setView($view);
  52. return $view;
  53. }
  54. /**
  55. * Retrieve view object
  56. *
  57. * @return Zend_View
  58. */
  59. public function getView()
  60. {
  61. if (null === $this->_view) {
  62. $options = $this->getOptions();
  63. $this->_view = new Zend_View($options);
  64. if (isset($options['doctype'])) {
  65. $this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
  66. if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
  67. $this->_view->headMeta()->setCharset($options['charset']);
  68. }
  69. }
  70. if (isset($options['contentType'])) {
  71. $this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
  72. }
  73. if (isset($options['assign']) && is_array($options['assign'])) {
  74. $this->_view->assign($options['assign']);
  75. }
  76. }
  77. return $this->_view;
  78. }
  79. }