3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
13 * Stream wrapper to convert markup of mostly-PHP templates into PHP prior to
16 * Based in large part on the example at
17 * http://www.php.net/manual/en/function.stream-wrapper-register.php
19 * As well as the example provided at:
20 * http://mikenaberezny.com/2006/02/19/symphony-templates-ruby-erb/
22 * Mike Naberezny (@link http://mikenaberezny.com)
23 * Paul M. Jones (@link http://paul-m-jones.com)
28 * Current stream position.
49 * Opens the script file and converts markup.
57 public function stream_open($path, $mode, $options, &$opened_path)
59 // get the view script source
60 $path = str_replace('zend.view://', '', $path);
61 $this->data
= file_get_contents($path);
64 * If reading the file failed, update our local stat store
65 * to reflect the real stat of the file, then return on failure
67 if ($this->data
=== false) {
68 $this->stat
= stat($path);
73 * Convert <?= ?> to long-form <?php echo ?> and <?php ?> to <?php ?>
76 $this->data
= preg_replace('/\<\?\=/', "<?php echo ", $this->data
);
77 $this->data
= preg_replace('/<\?(?!xml|php)/s', '<?php ', $this->data
);
80 * file_get_contents() won't update PHP's stat cache, so we grab a stat
81 * of the file to prevent additional reads should the script be
82 * requested again, which will make include() happy.
84 $this->stat
= stat($path);
90 * Included so that __FILE__ returns the appropriate info
94 public function url_stat()
100 * Reads from the stream.
105 public function stream_read($count)
107 $ret = substr($this->data
, $this->pos
, $count);
108 $this->pos +
= strlen($ret);
113 * Tells the current position in the stream.
117 public function stream_tell()
123 * Tells if we are at the end of the stream.
127 public function stream_eof()
129 return $this->pos
>= strlen($this->data
);
137 public function stream_stat()
143 * Seek to a specific point in the stream.
149 public function stream_seek($offset, $whence)
153 if ($offset < strlen($this->data
) && $offset >= 0) {
154 $this->pos
= $offset;
163 $this->pos +
= $offset;
171 if (strlen($this->data
) +
$offset >= 0) {
172 $this->pos
= strlen($this->data
) +
$offset;