Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 |
<?php
|
|
2 |
/**
|
|
3 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
4 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
5 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
6 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
7 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
8 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
9 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
10 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
11 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
12 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
13 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
14 |
*
|
|
15 |
* This software consists of voluntary contributions made by many individuals
|
|
16 |
* and is licensed under the LGPL. For more information please see
|
|
17 |
* <http://phing.info>.
|
|
18 |
*/
|
|
19 |
|
|
20 |
/**
|
|
21 |
* Extended file stream wrapper class which auto-creates directories
|
|
22 |
*
|
|
23 |
* @author Michiel Rook <mrook@php.net>
|
|
24 |
* @package phing.util
|
|
25 |
*/
|
|
26 |
class ExtendedFileStream |
|
27 |
{
|
|
28 |
private $fp = null; |
|
29 |
|
|
30 |
public static function registerStream() |
|
31 |
{
|
|
32 |
if (!in_array("efile", stream_get_wrappers())) { |
|
33 |
stream_wrapper_register("efile", "ExtendedFileStream"); |
|
34 |
}
|
|
35 |
}
|
|
36 |
|
|
37 |
public static function unregisterStream() |
|
38 |
{
|
|
39 |
stream_wrapper_unregister("efile"); |
|
40 |
}
|
|
41 |
|
|
42 |
/**
|
|
43 |
* @param $path
|
|
44 |
*/
|
|
45 |
private function createDirectories($path) |
|
46 |
{
|
|
47 |
$f = new PhingFile($path); |
|
48 |
if (!$f->exists()) { |
|
49 |
$f->mkdirs(); |
|
50 |
}
|
|
51 |
}
|
|
52 |
|
|
53 |
// @codingStandardsIgnoreStart
|
|
54 |
/**
|
|
55 |
* @param $path
|
|
56 |
* @param $mode
|
|
57 |
* @param $options
|
|
58 |
* @param $opened_path
|
|
59 |
* @return bool
|
|
60 |
* @throws IOException
|
|
61 |
*/
|
|
62 |
public function stream_open($path, $mode, $options, &$opened_path) |
|
63 |
{
|
|
64 |
// if we're on Windows, urldecode() the path again
|
|
65 |
if (FileSystem::getFileSystem()->getSeparator() == '\\') { |
|
66 |
$path = urldecode($path); |
|
67 |
}
|
|
68 |
|
|
69 |
$filepath = substr($path, 8); |
|
70 |
|
|
71 |
$this->createDirectories(dirname($filepath)); |
|
72 |
|
|
73 |
$this->fp = fopen($filepath, $mode); |
|
74 |
|
|
75 |
if (!$this->fp) { |
|
76 |
throw new BuildException("Unable to open stream for path {$path}"); |
|
77 |
}
|
|
78 |
|
|
79 |
return true; |
|
80 |
}
|
|
81 |
|
|
82 |
public function stream_close() |
|
83 |
{
|
|
84 |
fclose($this->fp); |
|
85 |
$this->fp = null; |
|
86 |
}
|
|
87 |
|
|
88 |
/**
|
|
89 |
* @param $count
|
|
90 |
* @return string
|
|
91 |
*/
|
|
92 |
public function stream_read($count) |
|
93 |
{
|
|
94 |
return fread($this->fp, $count); |
|
95 |
}
|
|
96 |
|
|
97 |
/**
|
|
98 |
* @param $data
|
|
99 |
* @return int
|
|
100 |
*/
|
|
101 |
public function stream_write($data) |
|
102 |
{
|
|
103 |
return fwrite($this->fp, $data); |
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* @return bool
|
|
108 |
*/
|
|
109 |
public function stream_eof() |
|
110 |
{
|
|
111 |
return feof($this->fp); |
|
112 |
}
|
|
113 |
|
|
114 |
/**
|
|
115 |
* @return int
|
|
116 |
*/
|
|
117 |
public function stream_tell() |
|
118 |
{
|
|
119 |
return ftell($this->fp); |
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
* @param $offset
|
|
124 |
* @param $whence
|
|
125 |
* @return int
|
|
126 |
*/
|
|
127 |
public function stream_seek($offset, $whence) |
|
128 |
{
|
|
129 |
return fseek($this->fp, $offset, $whence); |
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* @return bool
|
|
134 |
*/
|
|
135 |
public function stream_flush() |
|
136 |
{
|
|
137 |
return fflush($this->fp); |
|
138 |
}
|
|
139 |
|
|
140 |
/**
|
|
141 |
* @return array
|
|
142 |
*/
|
|
143 |
public function stream_stat() |
|
144 |
{
|
|
145 |
return fstat($this->fp); |
|
146 |
}
|
|
147 |
// @codingStandardsIgnoreEnd
|
|
148 |
|
|
149 |
/**
|
|
150 |
* @param $path
|
|
151 |
* @return bool
|
|
152 |
*/
|
|
153 |
public function unlink($path) |
|
154 |
{
|
|
155 |
return false; |
|
156 |
}
|
|
157 |
|
|
158 |
/**
|
|
159 |
* @param $path_from
|
|
160 |
* @param $path_to
|
|
161 |
* @return bool
|
|
162 |
*/
|
|
163 |
public function rename($path_from, $path_to) |
|
164 |
{
|
|
165 |
return false; |
|
166 |
}
|
|
167 |
|
|
168 |
/**
|
|
169 |
* @param $path
|
|
170 |
* @param $mode
|
|
171 |
* @param $options
|
|
172 |
* @return bool
|
|
173 |
*/
|
|
174 |
public function mkdir($path, $mode, $options) |
|
175 |
{
|
|
176 |
return false; |
|
177 |
}
|
|
178 |
|
|
179 |
/**
|
|
180 |
* @param $path
|
|
181 |
* @param $options
|
|
182 |
* @return bool
|
|
183 |
*/
|
|
184 |
public function rmdir($path, $options) |
|
185 |
{
|
|
186 |
return false; |
|
187 |
}
|
|
188 |
}
|
Read our documentation on viewing source code .