View.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * Abstract master class for extension.
  23. */
  24. require_once 'Zend/View/Abstract.php';
  25. /**
  26. * Concrete class for handling view scripts.
  27. *
  28. * @category Zend
  29. * @package Zend_View
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_View extends Zend_View_Abstract
  34. {
  35. /**
  36. * Whether or not to use streams to mimic short tags
  37. * @var bool
  38. */
  39. private $_useViewStream = false;
  40. /**
  41. * Whether or not to use stream wrapper if short_open_tag is false
  42. * @var bool
  43. */
  44. private $_useStreamWrapper = false;
  45. /**
  46. * Constructor
  47. *
  48. * Register Zend_View_Stream stream wrapper if short tags are disabled.
  49. *
  50. * @param array $config
  51. * @return void
  52. */
  53. public function __construct($config = array())
  54. {
  55. $this->_useViewStream = (bool) ini_get('short_open_tag') ? false : true;
  56. if ($this->_useViewStream) {
  57. if (!in_array('zend.view', stream_get_wrappers())) {
  58. require_once 'Zend/View/Stream.php';
  59. stream_wrapper_register('zend.view', 'Zend_View_Stream');
  60. }
  61. }
  62. if (array_key_exists('useStreamWrapper', $config)) {
  63. $this->setUseStreamWrapper($config['useStreamWrapper']);
  64. }
  65. parent::__construct($config);
  66. }
  67. /**
  68. * Set flag indicating if stream wrapper should be used if short_open_tag is off
  69. *
  70. * @param bool $flag
  71. * @return Zend_View
  72. */
  73. public function setUseStreamWrapper($flag)
  74. {
  75. $this->_useStreamWrapper = (bool) $flag;
  76. return $this;
  77. }
  78. /**
  79. * Should the stream wrapper be used if short_open_tag is off?
  80. *
  81. * @return bool
  82. */
  83. public function useStreamWrapper()
  84. {
  85. return $this->_useStreamWrapper;
  86. }
  87. /**
  88. * Includes the view script in a scope with only public $this variables.
  89. *
  90. * @param string The view script to execute.
  91. */
  92. protected function _run()
  93. {
  94. if ($this->_useViewStream && $this->useStreamWrapper()) {
  95. include 'zend.view://' . func_get_arg(0);
  96. } else {
  97. include func_get_arg(0);
  98. }
  99. }
  100. }