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.
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
22 * Stream wrapper to convert markup of mostly-PHP templates into PHP prior to
25 * Based in large part on the example at
26 * http://www.php.net/manual/en/function.stream-wrapper-register.php
28 * As well as the example provided at:
29 * http://mikenaberezny.com/2006/02/19/symphony-templates-ruby-erb/
31 * Mike Naberezny (@link http://mikenaberezny.com)
32 * Paul M. Jones (@link http://paul-m-jones.com)
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_View_Stream
42 * Current stream position.
63 * Opens the script file and converts markup.
65 public function stream_open($path, $mode, $options, &$opened_path)
67 // get the view script source
68 $path = str_replace('zend.view://', '', $path);
69 $this->_data
= file_get_contents($path);
72 * If reading the file failed, update our local stat store
73 * to reflect the real stat of the file, then return on failure
75 if ($this->_data
=== false) {
76 $this->_stat
= stat($path);
81 * Convert <?= ?> to long-form <?php echo ?> and <? ?> to <?php ?>
84 $this->_data
= preg_replace('/\<\?\=/', "<?php echo ", $this->_data
);
85 $this->_data
= preg_replace('/<\?(?!xml|php)/s', '<?php ', $this->_data
);
88 * file_get_contents() won't update PHP's stat cache, so we grab a stat
89 * of the file to prevent additional reads should the script be
90 * requested again, which will make include() happy.
92 $this->_stat
= stat($path);
98 * Included so that __FILE__ returns the appropriate info
102 public function url_stat()
108 * Reads from the stream.
110 public function stream_read($count)
112 $ret = substr($this->_data
, $this->_pos
, $count);
113 $this->_pos +
= strlen($ret);
119 * Tells the current position in the stream.
121 public function stream_tell()
128 * Tells if we are at the end of the stream.
130 public function stream_eof()
132 return $this->_pos
>= strlen($this->_data
);
139 public function stream_stat()
146 * Seek to a specific point in the stream.
148 public function stream_seek($offset, $whence)
152 if ($offset < strlen($this->_data
) && $offset >= 0) {
153 $this->_pos
= $offset;
162 $this->_pos +
= $offset;
170 if (strlen($this->_data
) +
$offset >= 0) {
171 $this->_pos
= strlen($this->_data
) +
$offset;