fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / View / Stream.php
blobb4994f2dc523ba77a50632b81ea0399df94b6db4
1 <?php
2 /**
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
8 */
10 namespace Zend\View;
12 /**
13 * Stream wrapper to convert markup of mostly-PHP templates into PHP prior to
14 * include().
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/
21 * written by
22 * Mike Naberezny (@link http://mikenaberezny.com)
23 * Paul M. Jones (@link http://paul-m-jones.com)
25 class Stream
27 /**
28 * Current stream position.
30 * @var int
32 protected $pos = 0;
34 /**
35 * Data for streaming.
37 * @var string
39 protected $data;
41 /**
42 * Stream stats.
44 * @var array
46 protected $stat;
48 /**
49 * Opens the script file and converts markup.
51 * @param string $path
52 * @param $mode
53 * @param $options
54 * @param $opened_path
55 * @return bool
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);
63 /**
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);
69 return false;
72 /**
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);
79 /**
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);
86 return true;
89 /**
90 * Included so that __FILE__ returns the appropriate info
92 * @return array
94 public function url_stat()
96 return $this->stat;
99 /**
100 * Reads from the stream.
102 * @param int $count
103 * @return string
105 public function stream_read($count)
107 $ret = substr($this->data, $this->pos, $count);
108 $this->pos += strlen($ret);
109 return $ret;
113 * Tells the current position in the stream.
115 * @return int
117 public function stream_tell()
119 return $this->pos;
123 * Tells if we are at the end of the stream.
125 * @return bool
127 public function stream_eof()
129 return $this->pos >= strlen($this->data);
133 * Stream statistics.
135 * @return array
137 public function stream_stat()
139 return $this->stat;
143 * Seek to a specific point in the stream.
145 * @param $offset
146 * @param $whence
147 * @return bool
149 public function stream_seek($offset, $whence)
151 switch ($whence) {
152 case SEEK_SET:
153 if ($offset < strlen($this->data) && $offset >= 0) {
154 $this->pos = $offset;
155 return true;
156 } else {
157 return false;
159 break;
161 case SEEK_CUR:
162 if ($offset >= 0) {
163 $this->pos += $offset;
164 return true;
165 } else {
166 return false;
168 break;
170 case SEEK_END:
171 if (strlen($this->data) + $offset >= 0) {
172 $this->pos = strlen($this->data) + $offset;
173 return true;
174 } else {
175 return false;
177 break;
179 default:
180 return false;