2
0

View.php 2.9 KB

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