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