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
|
|
|
namespace Phing\Io; |
21
|
|
|
|
22
|
|
|
use Phing\Exception\BuildException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Extended file stream wrapper class which auto-creates directories |
26
|
|
|
* |
27
|
|
|
* @author Michiel Rook <[email protected]> |
28
|
|
|
* @package phing.util |
29
|
|
|
*/ |
30
|
|
|
class ExtendedFileStream |
31
|
|
|
{ |
32
|
|
|
private $fp = null; |
33
|
|
|
|
34
|
|
|
public static function registerStream() |
35
|
|
|
{ |
36
|
|
|
if (!in_array("efile", stream_get_wrappers())) { |
37
|
|
|
stream_wrapper_register("efile", "ExtendedFileStream"); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function unregisterStream() |
42
|
|
|
{ |
43
|
|
|
stream_wrapper_unregister("efile"); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param $path |
48
|
|
|
*/ |
49
|
|
|
private function createDirectories($path) |
50
|
|
|
{ |
51
|
|
|
$f = new File($path); |
52
|
|
|
if (!$f->exists()) { |
53
|
|
|
$f->mkdirs(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// @codingStandardsIgnoreStart |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param $path |
61
|
|
|
* @param $mode |
62
|
|
|
* @param $options |
63
|
|
|
* @param $opened_path |
64
|
|
|
* @return bool |
65
|
|
|
* @throws IOException |
66
|
|
|
*/ |
67
|
|
|
public function stream_open($path, $mode, $options, &$opened_path) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
// if we're on Windows, urldecode() the path again |
70
|
|
|
if (FileSystem::getFileSystem()->getSeparator() == '\\') { |
71
|
|
|
$path = urldecode($path); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$filepath = substr($path, 8); |
75
|
|
|
|
76
|
|
|
$this->createDirectories(dirname($filepath)); |
77
|
|
|
|
78
|
|
|
$this->fp = fopen($filepath, $mode); |
79
|
|
|
|
80
|
|
|
if (!$this->fp) { |
81
|
|
|
throw new BuildException("Unable to open stream for path {$path}"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function stream_close() |
88
|
|
|
{ |
89
|
|
|
fclose($this->fp); |
90
|
|
|
$this->fp = null; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param $count |
95
|
|
|
* @return string |
96
|
|
|
*/ |
97
|
|
|
public function stream_read($count) |
98
|
|
|
{ |
99
|
|
|
return fread($this->fp, $count); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param $data |
104
|
|
|
* @return int |
105
|
|
|
*/ |
106
|
|
|
public function stream_write($data) |
107
|
|
|
{ |
108
|
|
|
return fwrite($this->fp, $data); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
public function stream_eof() |
115
|
|
|
{ |
116
|
|
|
return feof($this->fp); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return int |
121
|
|
|
*/ |
122
|
|
|
public function stream_tell() |
123
|
|
|
{ |
124
|
|
|
return ftell($this->fp); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param $offset |
129
|
|
|
* @param $whence |
130
|
|
|
* @return int |
131
|
|
|
*/ |
132
|
|
|
public function stream_seek($offset, $whence) |
133
|
|
|
{ |
134
|
|
|
return fseek($this->fp, $offset, $whence); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
|
|
public function stream_flush() |
141
|
|
|
{ |
142
|
|
|
return fflush($this->fp); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
|
public function stream_stat() |
149
|
|
|
{ |
150
|
|
|
return fstat($this->fp); |
151
|
|
|
} |
152
|
|
|
// @codingStandardsIgnoreEnd |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param $path |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
|
|
public function unlink($path) |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
return false; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param $path_from |
165
|
|
|
* @param $path_to |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
public function rename($path_from, $path_to) |
|
|
|
|
169
|
|
|
{ |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param $path |
175
|
|
|
* @param $mode |
176
|
|
|
* @param $options |
177
|
|
|
* @return bool |
178
|
|
|
*/ |
179
|
|
|
public function mkdir($path, $mode, $options) |
|
|
|
|
180
|
|
|
{ |
181
|
|
|
return false; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param $path |
186
|
|
|
* @param $options |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function rmdir($path, $options) |
|
|
|
|
190
|
|
|
{ |
191
|
|
|
return false; |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.